-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlc-844.java
More file actions
27 lines (25 loc) · 734 Bytes
/
lc-844.java
File metadata and controls
27 lines (25 loc) · 734 Bytes
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
class Solution {
public boolean backspaceCompare(String S, String T) {
Stack<Character> ss = new Stack();
Stack<Character> st = new Stack();
for(char a : S.toCharArray()) {
if(a == '#' && !ss.isEmpty()) {
ss.pop();
}else if(a != '#'){
ss.push(a);
}
}
for(char a : T.toCharArray()) {
if(a == '#' && !st.isEmpty()) {
st.pop();
}else if(a != '#'){
st.push(a);
}
}
if(st.size()!=ss.size()) return false;
while(!st.isEmpty()) {
if(st.pop() != ss.pop()) return false;
}
return true;
}
}