【LeetCode 38_字符串_算术运算】Count and Say

 1 string countAndSay(int n)
 2 {
 3     string res;
 4     if (n <= 0)
 5         return res;
 6 
 7     res = "1";
 8     while (n-- > 1) {
 9         int len = res.size();
10         int i, j;
11         string resTmp;
12 
13         for (i = 0; i < len; i = j) {
14             char ch = res[i];
15 
16             for (j = i + 1; j < len; ++j) {
17                 if (ch != res[j])
18                     break;
19             }
20 
21             resTmp = resTmp + (char)(j - i + '0') + ch;
22         }
23         res = resTmp;
24     }
25     return res;
26 }

 

相关文章:

  • 2021-07-07
  • 2021-10-02
  • 2021-09-10
  • 2021-11-14
  • 2021-08-15
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-06-16
  • 2021-07-09
  • 2022-02-14
  • 2021-07-29
  • 2022-02-05
相关资源
相似解决方案