forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_844.java
25 lines (23 loc) · 785 Bytes
/
_844.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
package com.fishercoder.solutions;
public class _844 {
public static class Solution1 {
public boolean backspaceCompare(String S, String T) {
String processedS = process(S);
String processedT = process(T);
return processedS.equals(processedT);
}
private String process(String str) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '#') {
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
} else {
sb.append(str.charAt(i));
}
}
return sb.reverse().toString();
}
}
}