Skip to content

Commit ff995e3

Browse files
committed
update remove-duplicate-letter.py
1 parent fe30032 commit ff995e3

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Python/remove-duplicate-letters.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Time: O(n)
22
# Space: O(k), k is size of the alphabet
33

4-
import collections
4+
from collections import Counter
55

66

77
class Solution(object):
@@ -10,9 +10,7 @@ def removeDuplicateLetters(self, s):
1010
:type s: str
1111
:rtype: str
1212
"""
13-
remaining = collections.defaultdict(int)
14-
for c in s:
15-
remaining[c] += 1
13+
remaining = Counter(s)
1614

1715
in_stack, stk = set(), []
1816
for c in s:
@@ -23,4 +21,3 @@ def removeDuplicateLetters(self, s):
2321
in_stack.add(c)
2422
remaining[c] -= 1
2523
return "".join(stk)
26-

0 commit comments

Comments
 (0)