Skip to content

Commit 57de0e8

Browse files
authored
Create Solution.java
1 parent 8ea4e2c commit 57de0e8

File tree

1 file changed

+14
-0
lines changed
  • solution/1047.Remove All Adjacent Duplicates In String

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public String removeDuplicates(String S) {
3+
char[] cs = new char[S.length()];
4+
int top = -1;
5+
for (char c : S.toCharArray()) {
6+
if (top >= 0 && c == cs[top]) {
7+
--top;
8+
} else {
9+
cs[++top] = c;
10+
}
11+
}
12+
return String.valueOf(cs, 0, top + 1);
13+
}
14+
}

0 commit comments

Comments
 (0)