728x90
LeetCode-316
Remove Duplicate Letters : Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.
note :
Answer
:::python
class Solution:
def removeDuplicateLetters(self, s: str) -> str:
for char in sorted(set(s)):
suffix = s[s.index(char):]
if set(s)==set(suffix):
return char + self.removeDuplicateLetters(suffix.replace(char,''))
return ''
Result : 55ms Memory: 14.1mb
๋ฐ์ํ
'๐ข One step' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[leetcode-225] Implement Queue using Stacks (0) | 2023.04.05 |
---|---|
[leetcode 739] Daily Temperature (0) | 2023.04.03 |
[leetcode-20] Valid Parenthese (0) | 2023.03.29 |
[leetcode 92] Reverse Linked List II (0) | 2023.03.26 |
[leetcode-24] Swap-Nodes-In-Pairs_2 (0) | 2023.03.21 |