Leetcode Count and Say
来源:互联网 发布:手机淘宝掌柜热卖在哪 编辑:程序博客网 时间:2024/06/05 05:52
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.
原题:点击打开链接
class Solution {public: string countAndSay(int n){ string s = "1"; while(--n > 0){ string tmp; tmp.clear(); int size = s.length(), cnt = 1; char lastChar = s[0]; for(int i=1;i<size;i++){ if(lastChar == s[i]){ cnt++; }else{ tmp += cnt + '0'; tmp += lastChar; lastChar = s[i]; cnt = 1; } } tmp += cnt + '0'; tmp += lastChar; s = tmp; } 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
- android文件选择的实现
- DES/3DES/AES 加密算法区别
- LeetCode: Single Number II
- android--监听按键
- Intent常用系统调用
- Leetcode Count and Say
- 机器学习基础知识-回归与梯度下降法
- ZOJ--3574--Under Attack II【线段树+欧拉公式】
- 手动创建数据库脚本以及报错处理:ORA-01519ORA-00604ORA-30012
- 会场安排问题(南阳oj14)(贪心-区间不重叠)
- WEBERP测试实录:一 webERP安装
- C++ STL map类型简介
- android之Android.mk小结
- Opencv step by step - 自适应阈值