Leetcode 之Count and Say(35)
LeetCode and count 35
2023-09-14 08:57:33 时间
很有意思的一道题,不好想啊。
string getNext(string &s) { char start = s[0]; int count = 0; stringstream ss; for (int i = 0; i < s.size(); i++) { if (start == s[i]) { count++; } else { ss << count << start; count = 1; start = s[i]; } } ss << count << start; return ss.str(); } string countAndSay(int n) { string s = "1"; for (int i = 0; i < n; i++) s = getNext(s); }
相关文章
- Java实现 LeetCode 717 1比特与2比特字符(暴力)
- Java实现 LeetCode 696 计数二进制子串(暴力)
- Java实现 LeetCode 667 优美的排列 II(暴力)
- Java实现 LeetCode 649 Dota2 参议院(暴力大法)
- Java实现 LeetCode 1两数之和
- 网络号 = IP和子网掩码的每位数AND 主机号 掩码取反与IP地址and运算
- leetcode - Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode【8】. String to Integer (atoi) --java实现
- [LeetCode] 201. Bitwise AND of Numbers Range ☆☆☆(数字范围按位与)
- 73_leetcode_Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode] 032. Longest Valid Parentheses (Hard) (C++)
- LeetCode 122 Best Time to Buy and Sell Stock II
- leetcode第一刷_Construct Binary Tree from Inorder and Postorder Traversal
- Best Time to Buy and Sell Stock I,II,III [leetcode]
- leetcode 717. 1-bit and 2-bit Characters
- 【LeetCode】跳跃游戏II