-
Notifications
You must be signed in to change notification settings - Fork 0
/
append_and_delete.java
74 lines (50 loc) · 1.33 KB
/
append_and_delete.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class append_and_delete {
public static String appendAndDelete(String s, String t, int k) {
if(k>=s.length()+t.length()){
return "Yes";
}
else{
int x=0;
for(int i=0;i<Math.min(s.length(),t.length());i++){
if(s.charAt(i)==t.charAt(i)){
x++;
}
else{
break;
}
}
int diff_char=s.length()-x+t.length()-x;
if(k==diff_char){
return "Yes";
}
else if(k<diff_char){
return "No";
}
else{
if((k-diff_char)%2==0){
return "Yes";
}
else{
return "No";
}
}
}
}
}
class Solution {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String s = scan.nextLine();
String t = scan.nextLine();
int k = scan.nextInt();
String result = append_and_delete.appendAndDelete(s, t, k);
System.out.println(result);
}
}