[Leetcode] 38 - Count and Say
来源:互联网 发布:如何进入淘宝试用中心 编辑:程序博客网 时间:2024/04/20 21:15
原题链接:https://oj.leetcode.com/problems/count-and-say/
这道题其实考的还是细心了,外层循环n,内存循环当前字符长度。
class Solution {public: string countAndSay(int n) { string res = ""; if (n < 0) return res; res = "1"; int i = 1; while (i < n) { string temp = ""; char prev = '-'; int count = 0; for (int j = 0; j < res.size(); ++j) { if (prev != res[j]) { if (prev != '-') { temp.push_back('0' + count); temp.push_back(prev); } prev = res[j]; count = 1; } else { ++count; } } temp.push_back('0' + count); temp.push_back(prev); ++i; res = temp; } return res; }};
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
- DOM 插入标记
- FZU 2178 礼物分配 (折半搜索+二分)
- JAVA方法DataOutputStream.writeBytes(String s)传递中文乱码问题
- spring 事件监听
- GLSL 内建函数
- [Leetcode] 38 - Count and Say
- 初步学习界面编程
- 为什么在12306买火车票要装根证书?
- 小马甲到了,特此纪念。
- Could not initialize class android.widget.TextView
- Unity 实现大转盘笔记
- 解决mysql中只能通过localhost访问不能通过ip访问的问题
- poj 1026 Cipher (置换群)
- IOS真机测试教程