Skip to content

Commit 56fd866

Browse files
committed
update readme
1 parent 7f5db2d commit 56fd866

9 files changed

+30
-93
lines changed

.github/test.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
0941-valid-mountain-array python easy
1+
0316-remove-duplicate-letters python medium
2+
1081-smallest-subsequence-of-distinct-characters python medium

0316-remove-duplicate-letters/0316-remove-duplicate-letters.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0316-remove-duplicate-letters/README.md

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
from collections import Counter
2-
3-
1+
# time complexity: O(n)
2+
# space complexity: O(n)
43
class Solution:
54
def removeDuplicateLetters(self, s: str) -> str:
6-
c = Counter(s)
7-
position = 0
8-
for i in range(len(s)):
9-
if s[i] < s[position]:
10-
position = i
11-
c[s[i]] -= 1
12-
if c[s[i]] == 0:
13-
break
14-
15-
return s[position] + self.removeDuplicateLetters(s[position:].replace(s[position], "")) if s else ""
5+
stack = []
6+
seen = set()
7+
lastCharIdx = {c: i for i, c in enumerate(s)}
8+
9+
for i, c in enumerate(s):
10+
if c not in seen:
11+
while stack and c < stack[-1] and i < lastCharIdx[stack[-1]]:
12+
seen.discard(stack.pop())
13+
seen.add(c)
14+
stack.append(c)
15+
16+
return ''.join(stack)
17+
18+
19+
s = "bcabc"
20+
print(Solution().removeDuplicateLetters(s))
21+
s = "cbacdcbc"
22+
print(Solution().removeDuplicateLetters(s))

Question_List_1001_2000.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
| 1074 | [Number of Submatrices That Sum to Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target/) | [Python](./Python/1074-number-of-submatrices-that-sum-to-target.py) | [Hard](./Readme/1074-number-of-submatrices-that-sum-to-target.md) |
4040
| 1075 | [Project Employees I](https://leetcode.com/problems/project-employees-i/) | [SQL](./SQL/1075-project-employees-i.sql) | [Easy](./Readme/1075-project-employees-i.md) |
4141
| 1079 | [Letter Tile Possibilities](https://leetcode.com/problems/letter-tile-possibilities) | [Python](./Python/1079-letter-tile-possibilities.py) | [Medium](./Readme/1079-letter-tile-possibilities.md) |
42+
| 1081 | [Smallest Subsequence of Distinct Characters](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters) | [Python](./Python/1081-smallest-subsequence-of-distinct-characters.py) | [Medium](./Readme/1081-smallest-subsequence-of-distinct-characters.md) |
4243
| 1086 | [High Five](https://leetcode.com/problems/high-five) | [Python](./Python/1086-high-five.py) | [Easy](./Readme/1086-high-five.md) |
4344
| 1087 | [Brace Expansion](https://leetcode.com/problems/brace-expansion) | [Python](./Python/1087-brace-expansion.py) | [Medium](./Readme/1087-brace-expansion.md) |
4445
| 1090 | [Largest Values From Labels](https://leetcode.com/problems/largest-values-from-labels) | [Python](./Python/1090-largest-values-from-labels.py) | [Medium](./Readme/1090-largest-values-from-labels.md) |

README.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,3 @@ It helps others discover the repo and keeps the project growing.
115115
---
116116

117117
Feedback / Questions → open an Issue or reach out on [LinkedIn](https://www.linkedin.com/in/hogan-l/)
118-
119-
<!---LeetCode Topics Start-->
120-
# LeetCode Topics
121-
## String
122-
| |
123-
| ------- |
124-
| [0316-remove-duplicate-letters](https://github.com/hogan-tech/leetcode-solution/tree/master/0316-remove-duplicate-letters) |
125-
| [1159-smallest-subsequence-of-distinct-characters](https://github.com/hogan-tech/leetcode-solution/tree/master/1159-smallest-subsequence-of-distinct-characters) |
126-
## Stack
127-
| |
128-
| ------- |
129-
| [0316-remove-duplicate-letters](https://github.com/hogan-tech/leetcode-solution/tree/master/0316-remove-duplicate-letters) |
130-
| [1159-smallest-subsequence-of-distinct-characters](https://github.com/hogan-tech/leetcode-solution/tree/master/1159-smallest-subsequence-of-distinct-characters) |
131-
## Greedy
132-
| |
133-
| ------- |
134-
| [0316-remove-duplicate-letters](https://github.com/hogan-tech/leetcode-solution/tree/master/0316-remove-duplicate-letters) |
135-
| [1159-smallest-subsequence-of-distinct-characters](https://github.com/hogan-tech/leetcode-solution/tree/master/1159-smallest-subsequence-of-distinct-characters) |
136-
## Monotonic Stack
137-
| |
138-
| ------- |
139-
| [0316-remove-duplicate-letters](https://github.com/hogan-tech/leetcode-solution/tree/master/0316-remove-duplicate-letters) |
140-
| [1159-smallest-subsequence-of-distinct-characters](https://github.com/hogan-tech/leetcode-solution/tree/master/1159-smallest-subsequence-of-distinct-characters) |
141-
<!---LeetCode Topics End-->

Readme/0316-remove-duplicate-letters.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
<h2><a href="https://leetcode.com/problems/remove-duplicate-letters/">316. Remove Duplicate Letters</a></h2><h3>Medium</h3><hr><div><p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p>
1+
<h2><a href="https://leetcode.com/problems/remove-duplicate-letters">316. Remove Duplicate Letters</a></h2><h3>Medium</h3><hr><p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p>
22

33
<p>&nbsp;</p>
44
<p><strong class="example">Example 1:</strong></p>
55

6-
<pre><strong>Input:</strong> s = "bcabc"
7-
<strong>Output:</strong> "abc"
6+
<pre>
7+
<strong>Input:</strong> s = &quot;bcabc&quot;
8+
<strong>Output:</strong> &quot;abc&quot;
89
</pre>
910

1011
<p><strong class="example">Example 2:</strong></p>
1112

12-
<pre><strong>Input:</strong> s = "cbacdcbc"
13-
<strong>Output:</strong> "acdb"
13+
<pre>
14+
<strong>Input:</strong> s = &quot;cbacdcbc&quot;
15+
<strong>Output:</strong> &quot;acdb&quot;
1416
</pre>
1517

1618
<p>&nbsp;</p>
@@ -23,4 +25,3 @@
2325

2426
<p>&nbsp;</p>
2527
<p><strong>Note:</strong> This question is the same as 1081: <a href="https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/" target="_blank">https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/</a></p>
26-
</div>
File renamed without changes.

0 commit comments

Comments
 (0)