386. 字典序排数

 1 class Solution 
 2 {
 3 public:
 4     vector<int> lexicalOrder(int n) 
 5     {
 6         set<string> hash;
 7         vector<int> res;
 8         for(int i = 1;i <= n;i ++)
 9         {
10             hash.insert(to_string(i));
11         }
12         for(auto it = hash.begin();it != hash.end();it ++)
13         {
14             res.push_back(atoi((*it).c_str()));
15         }
16         return res;
17     }
18 };

 

posted @ 2020-04-27 15:54  Jinxiaobo0509  阅读(111)  评论(0)    收藏  举报