<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

统计

  • 随笔 - 57
  • 文章 - 7
  • 评论 - 0
  • 引用 - 0

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

Blog

Coder 必备技巧

Compiler for Wurq

搜索

  •  

最新评论

阅读排行榜

评论排行榜

【LeeCode 2017/07/04】38. Count and Say
 1 class Solution {
 2 public:
 3     string countAndSay(int n) {
 4         list<int>v;
 5         v.push_back(1);
 6         while (--n)
 7         {
 8             list<int>tmp;
 9 
10             int num = -1;
11             int count = 0;
12             while (!v.empty())
13             {
14                 if (num == -1) {
15                     num = v.front();
16                     count++;
17                 }
18                 else if (v.front() == num)
19                 {
20                     count++;
21                 }
22                 else 
23                 {
24                     tmp.push_back(count);
25                     tmp.push_back(num);
26                     count = 0;
27                     num = v.front();
28                     count++;
29                 }
30                 v.pop_front();
31             }
32 
33             tmp.push_back(count);
34             tmp.push_back(num);
35 
36             v = tmp;
37         }
38 
39         string str = "1";
40 
41         if (!v.empty())
42             str = "";
43 
44         while (!v.empty()){
45             str += v.front() + '0';
46             v.pop_front();
47         }
48 
49         return str;
50     }
51 };
52 

posted on 2017-07-04 19:51 Wurq 阅读(125) 评论(0)  编辑 收藏 引用 所属分类: 【LeeCode 每日N题】


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理