码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 之Count and Say(35)

时间:2016-05-25 20:21:10      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

很有意思的一道题,不好想啊。

技术分享
string getNext(string &s)
      {
          char start = s[0];
          int count = 0;
          stringstream ss;
          for (int i = 0; i < s.size(); i++)
          {
              if (start == s[i])
              {
                  count++;
              }
              else
              {
                  ss << count << start;
                  count = 1;
                  start = s[i];
              }
          }
          ss << count << start;

          return ss.str();
      }

      string countAndSay(int n)
      {
          string s = "1";
          for (int i = 0; i < n; i++)
              s = getNext(s);
      }
View Code

 

Leetcode 之Count and Say(35)

标签:

原文地址:http://www.cnblogs.com/573177885qq/p/5528060.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!