Skip to content

Commit fbb378c

Browse files
committed
Sync LeetCode submission Runtime - 15 ms (98.20%), Memory - 18.6 MB (46.63%)
1 parent 228edae commit fbb378c

File tree

1 file changed

+9
-9
lines changed
  • 1128-remove-all-adjacent-duplicates-in-string

1 file changed

+9
-9
lines changed
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Approach 2: Stack
22

3-
# Time: O(N)
4-
# Space: O(N - D), D = length of all duplicates
3+
# n = string length, d = total length of all duplicates
4+
# Time: O(n)
5+
# Space: O(n - d)
56

67
class Solution:
78
def removeDuplicates(self, s: str) -> str:
8-
output = []
9-
9+
stack = []
1010
for ch in s:
11-
if output and ch == output[-1]:
12-
output.pop()
11+
if stack and ch == stack[-1]:
12+
stack.pop()
1313
else:
14-
output.append(ch)
15-
16-
return ''.join(output)
14+
stack.append(ch)
15+
16+
return ''.join(stack)
1717

0 commit comments

Comments
 (0)