首页 > 其他 > 详细

Leetcode-5086 Smallest Subsequence of Distinct Characters(不同字符的最小子序列)

时间:2019-06-09 13:38:49      阅读:228      评论:0      收藏:0      [点我收藏+]
 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

Leetcode-5086 Smallest Subsequence of Distinct Characters(不同字符的最小子序列)

原文:https://www.cnblogs.com/Asurudo/p/10993171.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!