LeetCodeOJ: 38. Count and Say
来源:互联网 发布:网游数据库 编辑:程序博客网 时间:2024/05/20 10:12
Total Accepted: 75530 Total Submissions: 265272 Difficulty: Easy
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 str1 = "1"; n--; while(n--){ string str2 = ""; for(int i = 0; i < str1.length();){ int cur_count = 0; char cur_n = str1[i]; while(cur_n == str1[i] && i < str1.length()){ cur_count++; i++; } str2 += (cur_count+'0'); str2 += cur_n; } str1 = str2; } return str1; }};
0 0
- LeetCodeOJ: 38. Count and Say
- LeetCodeOJ. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- hdu1058 Humble Numbers--DP
- boost的内存管理
- java实现一个二叉查找树的各种操作
- POJ 3696 The Luckiest Number 欧拉函数
- Go语言学习(二)常量
- LeetCodeOJ: 38. Count and Say
- oracle函数索引
- strcmp函数的实现方法
- 表单提交返回json 弹出下载框
- 云计算时代的到来
- linux 知识体系精炼版
- hdu 3018 欧拉路定理+并查集
- hive大数据倾斜总结
- Deep learning:(龙星计划2013深度学习课程小总结)