Skip to content

Commit 01d4b6f

Browse files
authored
Create Backspace String Compare
1 parent e17a194 commit 01d4b6f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Backspace String Compare

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class Solution {
2+
public boolean backspaceCompare(String S, String T) {
3+
ArrayList<Character> s = new ArrayList<>();
4+
ArrayList<Character> t = new ArrayList<>();
5+
int count = 0;
6+
for(int i = 0; i<S.length(); i++){
7+
if(S.charAt(i) != '#'){
8+
count++;
9+
s.add(S.charAt(i));
10+
}
11+
else{
12+
if(count >= 1){
13+
count--;
14+
s.remove(count);
15+
//count--;
16+
}
17+
}
18+
//System.out.println(s);
19+
}
20+
count = 0;
21+
for(int i = 0; i<T.length(); i++){
22+
if(T.charAt(i) != '#'){
23+
count++;
24+
t.add(T.charAt(i));
25+
}
26+
else{
27+
if(count >= 1){
28+
count--;
29+
t.remove(count);
30+
//count--;
31+
}
32+
}
33+
//System.out.println(t);
34+
}
35+
36+
37+
if(s.size() != t.size()){
38+
return false;
39+
}
40+
if(s.size() == t.size() && s.size() == 0){
41+
return true;
42+
}
43+
for(int i = 0; i<s.size(); i++){
44+
if(s.get(i) != t.get(i)){
45+
return false;
46+
}
47+
}
48+
return true;
49+
}
50+
}

0 commit comments

Comments
 (0)