1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
2 class Solution
3 {
4 public:
5 string smallestSubsequence(string text)
6 {
7 int vis[26];
8 deque<char> deque1;
9 map<char,int> map1;
10
11 deque1.clear();
12 map1.clear();
13 int len=text.size();
14 for(int i=0; i<len; i++)
15 {
16 vis[text[i]-'a']=0;
17 map1[text[i]]++;
18 }
19 for(int i=0; i<len; i++)
20 {
21 map1[text[i]]--;
22 if(vis[text[i]-'a'])
23 continue;
24 while(!deque1.empty()&&deque1.back()>text[i]&&map1[deque1.back()]>0)
25 {
26 vis[deque1.back()-'a']=0;
27 deque1.pop_back();
28 }
29 deque1.push_back(text[i]);
30 vis[text[i]-'a']=1;
31 }
32 string rnt;
33 while(!deque1.empty())
34 {
35 rnt += deque1.front();
36 deque1.pop_front();
37 }
38 return rnt;
39 }
40 };
https://blog.csdn.net/kangyan__/article/details/75308651