Count and Say leetcode java
题目:
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.
题解:
题目说的实在是太不明白了。。。
解释一下就是,输入n,那么我就打出第n行的字符串。
怎么确定第n行字符串呢?他的这个是有规律的。
n = 1时,打印一个1。
n = 2时,看n=1那一行,念:1个1,所以打印:11。
n = 3时,看n=2那一行,念:2个1,所以打印:21。
n = 4时,看n=3那一行,念:一个2一个1,所以打印:1211。
以此类推。(注意这里n是从1开始的)
所以构建当前行的字符串要依据上一行的字符串。 count++;
res.append(count);
res.append(curRes.charAt(j-1));
count = 1;
}
}
res.append(count);
res.append(curRes.charAt(curRes.length()-1));
curRes = res.toString();
start++;
}
}
Reference:http://blog.csdn.net/linhuanmars/article/details/20679963
Count and Say leetcode java的更多相关文章
- N-Queens II leetcode java
题目: Follow up for N-Queens problem. Now, instead outputting board configurations, return the total n ...
- LeetCode算法题-Count Binary Substrings(Java实现)
这是悦乐书的第293次更新,第311篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第161题(顺位题号是696).给定一个字符串s,计算具有相同数字0和1的非空且连续子串 ...
- Count and Say leetcode
题目链接 The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 11 ...
- Single Number II leetcode java
问题描述: Given an array of integers, every element appears three times except for one. Find that single ...
- Regular Expression Matching leetcode java
题目: Implement regular expression matching with support for '.' and '*'. '.' Matches any single chara ...
- Unique Binary Search Trees leetcode java
题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For e ...
- Sqrt(int x) leetcode java
Reference: http://blog.csdn.net/lbyxiafei/article/details/9375735 题目: Implement int sqrt(int x). Co ...
- 696. Count Binary Substrings - LeetCode
Question 696. Count Binary Substrings Example1 Input: "00110011" Output: 6 Explanation: Th ...
- Spark: 单词计数(Word Count)的MapReduce实现(Java/Python)
1 导引 我们在博客<Hadoop: 单词计数(Word Count)的MapReduce实现 >中学习了如何用Hadoop-MapReduce实现单词计数,现在我们来看如何用Spark来 ...
随机推荐
- android 上下边框线
<!-- 连框颜色值 --> <item> <shape> <solid android:color="@android:color/backgro ...
- Moment.js 一款JS时间封装库
链接地址:http://momentjs.cn/docs/#/displaying/difference/
- URAL 1962 In Chinese Restaurant 数学
In Chinese Restaurant 题目连接: http://acm.hust.edu.cn/vjudge/contest/123332#problem/B Description When ...
- CentOS 7下安装nexus 3
安装nexus 3的几个注意事项: 1.nexus 3和nexus 2不一样,nexus 2可以搜索Maven主仓库的包,但在nexus 3不能,只能搜索缓存过的包. 2.安装时关心的点在于运行环境, ...
- MikroTik RouterOS U盘安装工具netinstall的使用
注意: 1.此工具我没测试成功,比如把一个U盘用这个工具制作好之后,实质上插入电脑启动会有卡死现象,不太稳定. 2.其实官方提供的教程很大一部分是这样的意思,比如把外接硬盘以USB或者SATA的形式插 ...
- JAVA 对象序列化(二)——Externalizable
Java默认的序列化机制非常简单,而且序列化后的对象不需要再次调用构造器重新生成,但是在实际中,我们可以会希望对象的某一部分不需要被序列化,或者说一个对象被还原之后,其内部的某些子对象需要重新创建,从 ...
- delphi 服务程序
http://www.delphifans.com/InfoView/Article_662.html 用Delphi创建服务程序 Windows 2000/XP和2003等支持一种叫做"服 ...
- 安装/使用 MVVMLight(转)
安装 MVVMLight Toolkit 为什么说是 MVVMLight Toolkit ?实际上我们一般安装的都是 MVVMLight Toolkit ,这个里面包含了工具就是在VS新建工程的时候你 ...
- Android 中的概念大集合
Intent: An Intent is an object that provides runtime binding between separate components (such as tw ...
- 警告 7 隐藏了继承的成员。如果是有意隐藏,请使用关键字 new
public new bool Print(string 承包方编码, MapPrint.My2Progress pMy2Progress, bool Label2ZJ)