leetcode 38 Count and Say
来源:互联网 发布:python开发过哪些软件? 编辑:程序博客网 时间:2024/06/02 02:58
The count-and-say sequence is the sequence of integers with the first five terms as following:
- 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 term of the count-and-say sequence.
class Solution {public: string countAndSay(int n) { if (n == 0) return string(""); string ret(1, '1'); for (int i = 2; i <= n; ++i) { string tmp; size_t size = ret.size(); char ch = ret[0]; size_t count = 1; for (size_t j = 1; j < size; ++j) { if (ch == ret[j]) count++; else { tmp += string(1, '0' + count) + string(1, ch); ch = ret[j]; count = 1; } } tmp += string(1, '0' + count) + string(1, ch); ret = tmp; } return ret; }};
阅读全文
0 0
- [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
- 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
- RHEL7/Centos7破解root密码
- Android Studio生成get,set,tostring,构造方法
- Spring黑马笔记入门四
- 给定一个二维数组包含X与O,将数组中与四边相连的O以及四边的O不变,其他O变为X
- 对Hibernate的session的理解
- leetcode 38 Count and Say
- Android Glide数据更新及内存缓存、硬盘缓存清理
- JAVA提高篇(24)--CharArrayReader、CharArrayWriter简介
- LeetCodeday01
- 简单易用的数据库调用类(增、删、查、改)
- php curl编码类型设置、文件上传与接收数据
- android java中遇到的异常及报错如何解决?
- HihoCoder 1317 题解
- 通信协议——uart