leetcode 038 —— Count and Say
来源:互联网 发布:意外的sql命令结尾 编辑:程序博客网 时间:2024/05/17 08:39
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 s ;s = s + '1';for (int i = 1; i <n; i++){int j = 0;int cnt = 0;while (j < s.size()){if (j == s.size() - 1){s.insert(j, 1,'1');break;}cnt = 0;while (j + cnt +1 < s.size() && s[j ] == s[j + cnt + 1]){cnt++; //cnt代表要删除的位数}s.erase(j, cnt);s.insert(j,1, char(cnt+1 + '0'));j = j + 2;}}return s;}}a;
0 0
- leetcode 038 —— 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 038 Count and Say
- LeetCode 038-Count and Say
- leetcode 038 Count and Say
- LeetCode 038 Count and Say
- LeetCode 038 Count and Say
- [LeetCode]038-Count And Say
- leetcode 038 Count and Say
- leetcode 038 Count and Say
- LeetCode 038 Count and Say
- LeetCode: Count and Say
- [LeetCode]Count and Say
- 图像傅里叶变换,幅度谱,相位谱
- ubuntu 14.04 下安装 LAMP环境
- Java基础---JVM内存管理以及垃圾回收机制
- java 文件上传
- USRP通信的结构体和常量(上位机、下位机共用)
- leetcode 038 —— Count and Say
- byte[]和InputStream的相互转换
- 图像加噪,各种滤波
- 如何解决“Offending key in ~/.ssh/known_hosts” file
- 前端(安卓)与服务器通信总结
- xdais xDM
- 【Java】字符串程序
- 从键盘上得到一个1到100的数字,打印这个数字的二进制。
- Apache-nutch-1.10 安装笔记(二)