1081. Smallest Subsequence of Distinct Characters Medium

@problem@discussion
#String#Stack#Greedy#Monotonic Stack



1/**
2 * [1081] Smallest Subsequence of Distinct Characters
3 *
4 * Given a string s, return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.
5 *  
6 * Example 1:
7 * 
8 * Input: s = "bcabc"
9 * Output: "abc"
10 * 
11 * Example 2:
12 * 
13 * Input: s = "cbacdcbc"
14 * Output: "acdb"
15 * 
16 *  
17 * Constraints:
18 * 
19 * 	1 <= s.length <= 1000
20 * 	s consists of lowercase English letters.
21 * 
22 *  
23 * Note: This question is the same as 316: <a href="https://leetcode.com/problems/remove-duplicate-letters/" target="_blank">https://leetcode.com/problems/remove-duplicate-letters/</a>
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/
28// discuss: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33    pub fn smallest_subsequence(s: String) -> String {
34        String::new()
35    }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_1081() {
46    }
47}
48


Back
© 2025 bowen.ge All Rights Reserved.