count and say leetcode c++
来源:互联网 发布:虚拟实验室软件下载 编辑:程序博客网 时间:2024/06/14 04:01
pay attention to n and the string.
it is easy to understand the code below.
class Solution {public: string countAndSay(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n< 0) return NULL; string seq = "1"; for(int i = 1; i < n; ++i) { //cout<<seq<<endl; string tmp = ""; int count=0; char current=seq[0]; int index = 0; while(index < seq.length()) { if(seq[index] == current) count++; else { tmp += to_string(count) + current; current = seq[index]; count = 1; } index++; } tmp += to_string(count) + current; seq = tmp; } return seq; }};
0 0
- [C++]LeetCode: 20 Count and Say
- 【leetcode c++】38 Count and Say
- 【C++】【LeetCode】38. Count and Say
- LeetCode c语言- 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
- [LeetCode] Count and Say
- Count and Say 【leetcode】
- poj 1703 Find them, Catch them 【并查集拓展】
- Windows PE文件结构简介
- POJ 1006
- Java进阶之JDBC知识点总结
- 常用元件封装
- count and say leetcode c++
- 摄像机标定用于机械臂抓举等(利用标定将图像上的点映射为三维坐标)
- 每天一道ACM(1003)--斐波那契数列
- POJ 1011
- android机子重启
- linux 如何控制cpu资源使用
- codevs1074 食物链(并查集+向量偏移)
- POJ 1067
- Codeforces Round #280 (Div. 2)