-
Notifications
You must be signed in to change notification settings - Fork 1
/
2_December.java
52 lines (50 loc) · 1.26 KB
/
2_December.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
class Solution {
int isItPossible(String S, String T, int M, int N) {
// code here
if(M!=N)return 0;
int a=0;
int b=0;
for(int i=0;i<N;i++){
if(S.charAt(i)=='A'){
a++;
}else if(S.charAt(i)=='B'){
b++;
}
if(T.charAt(i)=='A'){
a--;
}else if(T.charAt(i)=='B'){
b--;
}
}
if(a!=0 || b!=0)return 0;
int i=0;
int j=0;
while(i<N && j<N){
while(i<N && S.charAt(i)=='#')i++;
while(j<N && T.charAt(j)=='#')j++;
if(i==N || j==N)break;
if(S.charAt(i)=='A'){
if(T.charAt(j)=='A'){
if(j>i)return 0;
else{
i++;
j++;
}
}else{
return 0;
}
}else{
if(T.charAt(j)=='B'){
if(j<i)return 0;
else{
i++;
j++;
}
}else{
return 0;
}
}
}
return 1;
}
}