[LeetCode]38. Count and Say
来源:互联网 发布:网络光纤收发器 编辑:程序博客网 时间:2024/05/20 11:34
[LeetCode]38. Count and Say
题目描述
思路
字符串拼接,暴力遍历即可
代码
#include <iostream>#include <string>using namespace std;class Solution {public: string countAndSay(int n) { if (n == 0) return ""; string res = "1"; while (--n) { string cur = ""; for (int i = 0; i < res.size(); ++i) { int count = 1; while (i + 1 < res.size() && res[i] == res[i + 1]) { ++count; ++i; } cur += to_string(count) + res[i]; } res = cur; } return res; }};int main() { Solution s; cout << s.countAndSay(5) << endl; system("pause"); return 0;}
阅读全文
0 0
- [LeetCode]38.Count and Say
- LeetCode --- 38. Count and Say
- LeetCode 38.Count and Say
- [Leetcode] 38. Count and Say
- 38. Count and Say LeetCode
- Leetcode 38. Count and Say
- leetcode 38. Count and Say
- [leetcode] 38. Count and Say
- LeetCode-38.Count and Say
- LeetCode *** 38. Count and Say
- leetcode 38. Count and Say
- LeetCode-38. Count and Say
- LeetCode 38. Count and Say
- LeetCode 38. Count and Say
- Leetcode - 38. Count and Say
- LeetCode 38. Count and Say
- Leetcode 38. Count and Say
- LeetCode 38. Count and Say
- BMP格式详解
- Steam Roller UVALive
- Ubuntu14.04+Slam(模拟topic)
- 史上最全图像识别特征描述及代码
- KMP
- [LeetCode]38. Count and Say
- Math对象
- 简单加解密(三)
- 整理第十届河南省ACM省赛正解
- JDK-db
- 对于Spring中IOC的理解
- Tomcat在服务端Manager App无法打开
- leetcode题解-162. Find Peak Element
- Java 笔记----数据库操作(一)