LeetCode-Count and Say
来源:互联网 发布:桂纶镁 戴立忍 知乎 编辑:程序博客网 时间:2024/05/29 08:25
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
1
is read off as "one 1"
or 11
.11
is read off as "two 1s"
or 21
.21
is read off as "one 2
, then one 1"
or 1211
.
Given an integer n, generate the nth sequence.
Note: The sequence of integers will be represented as a string.
class Solution {public: string countAndSay(int n);};string Solution::countAndSay(int n){ string b = ""; if(n == 1) return "1"; if(n == 2) return "11"; string s = "11"; //ong long num = 2; for(int i = 2; i < n; i++) //变化次数就是 n-1; { for(int j = 0; j < s.size();4) { int k = j+1; while (k < s.size() && s[k] == s[j]) { k++; } b += (k - j + '0'); b += s[j]; j = k; } s = b; b = ""; } return s;}
0 0
- LeetCode: Count and Say
- [LeetCode]Count and Say
- LeetCode Count and Say
- [Leetcode] Count and Say
- Leetcode: Count and Say
- [LeetCode] Count and Say
- LeetCode Count and Say
- [LeetCode]Count and Say
- [LeetCode] Count and Say
- LeetCode-Count and Say
- LeetCode: Count and Say
- LeetCode - Count and Say
- [LeetCode] Count and Say
- Count and Say 【leetcode】
- [LeetCode] Count and Say
- Leetcode Count and Say
- LeetCode Count and Say
- LeetCode | Count and Say
- iOS开发拓展篇—UIDynamic(重力行为+碰撞检测)
- iOS开发拓展篇—UIDynamic(捕捉行为)
- linux下内存大小、起始地址的解析与修改
- 2014流水账总结-从无知到困惑
- iOS开发拓展篇—音效的播放
- LeetCode-Count and Say
- iOS开发拓展篇—音乐的播放
- Iterator java
- Tiger垃圾收集器的实现
- Szucoder Round #4 (div.2)
- MySql的级联关系
- iOS开发拓展篇—CoreLocation简单介绍
- 自己理解的自动化测试框架
- iOS开发拓展篇—CoreLocation定位服务