-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution844.java
More file actions
48 lines (45 loc) · 1.09 KB
/
Copy pathsolution844.java
File metadata and controls
48 lines (45 loc) · 1.09 KB
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
import java.util.Stack;
public class solution844 {
private Stack<Character> stackS;
private Stack<Character> stackT;
public solution844(){
stackS = new Stack<>();
stackT = new Stack<>();
}
public boolean backspaceCompare(String S, String T) {
for(int i = 0;i<S.length();i++)
{
if(S.charAt(i)!='#')
{
stackS.push(S.charAt(i));
}else{
if(!stackS.isEmpty())
{
stackS.pop();
}
}
}
for(int i = 0;i<T.length();i++)
{
if(T.charAt(i)!='#')
{
stackT.push(T.charAt(i));
}else{
if(!stackT.isEmpty())
{
stackT.pop();
}
}
}
if(stackS.size()!=stackT.size()){
return false;
}
while(!stackS.isEmpty()){
if(stackS.pop()!=stackT.pop())
{
return false;
}
}
return true;
}
}