LeetCode 38. Count and Say
来源:互联网 发布:月光软件站 编辑:程序博客网 时间:2024/05/12 05:41
问题
https://leetcode.com/problems/count-and-say/
解法
模拟法, n=100都会超时。
class Solution {public: string countAndSay(int n) { string ret; ret.push_back('1'); for (int i=2; i<=n; ++i){ string now; int cnt =1; for (int j=1; j< ret.size(); ++j) { if (ret[j] != ret[j-1]) { now.append(to_string(cnt)); now.push_back(ret[j-1]); cnt = 1; }else cnt++; } now.append(to_string(cnt)); now.push_back(ret[ret.size()-1]); ret = now; } return ret; }};
int 转 string to_string
string 转 int stoi
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
- AJAX+PHP+MYSQL实现登录页面
- Mybatis最入门---ResultMaps基本用法
- 四种Block Match算法
- java根据端口号的被占数量实现软负载
- 阿里云iptables80端口转发
- LeetCode 38. Count and Say
- Bzoj2820:YY的GCD:莫比乌斯反演
- Chomsky文法类型判断
- mysql++
- JavaWeb学习总结(十七)——JSP中的九个内置对象
- Android拍照或相册获取照片上传 (带图片剪裁)
- Linux系统RabbitMQ安装
- 带有阻尼效果(橡皮筋效果)跳动的Loading动画
- 算法