【Leetcode】Count and Say
来源:互联网 发布:现代诗集推荐 知乎 编辑:程序博客网 时间:2024/05/16 09:04
题目链接:https://leetcode.com/problems/count-and-say/
题目:
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.
思路:
题目看懂了就好做了。。
算法:
public String countAndSay(int n) { String r = "1"; for (int i = 1; i < n; i++) { String t = ""; int count = 0; String flag = r.charAt(0) + ""; for (int j = 0; j < r.length(); j++) { if ((r.charAt(j) + "").equals(flag)) { count++; } else { t += count + "" + flag; flag = r.charAt(j) + ""; count = 1; } } t += count + "" + flag; r = t; } return r; }
1 0
- 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 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
- Count and Say 【leetcode】
- [LeetCode] Count and Say
- Leetcode Count and Say
- LeetCode Count and Say
- LeetCode | Count and Say
- ECC
- {算法}YY矩阵乘法
- TCP管理的4种定时器
- 运动目标检测--光流法
- python Django错误解决:A server error occurred. Please contact the administrator.
- 【Leetcode】Count and Say
- linenoise源码解析
- 【Leetcode】Best Time to Buy and Sell Stock
- nova boot代码流程分析(五):VM启动从neutron-dhcp-agent获取IP与MAC
- linux安全防护中迅速排查的一些命令
- HashTable二次探测
- 准备自己写代码读取tif高程和影像
- 【Leetcode】House Robber
- 触发器