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来 ...
随机推荐
- Linux C语言编程学习笔记 (1)进程控制入门
想进行Linux系统开发已经很久了,一直没有付诸实践.今日终于开始学习Linux下的C语言编程,研究一天,终于大概弄明白了Linux系统进程管理的一些基本概念和编程方法,总结下来以方便大家学习和自己实 ...
- Ulipad安装、配置使用教程(附Ulipad下载)
一.安装Ulipad 因为ulipad编辑器使用的是wxpython编写的gui,所以我们需要第三方库wxpython的支持,这里我们先讲一下Ulipad在Windows系统环境下的安装: 1. 确实 ...
- 面向企业级的开源WebGIS解决方案--MapGuide(对比分析)
在技术特点.功能.架构等方面,MapGuide与其他WebGIS产品有什么区别?本文主要从此角度来介绍MapGuide的特性,以供参考. 本人选择了比较熟悉的几款WebGIS产品:MapServ ...
- Redis使用小结
Redis官方没有windows版本的,对于Windows环境的redis,有如下两个方案 微软的移植版本,但只支持到3.2 下载地址 win10及以上的版本直接通过win10的liunx子系统执行 ...
- Ubuntu 中启用 root 帐号
参考:http://linuxtoy.org/archives/howto_enable_ubuntu_root_account.html 如果你实在需要在 Ubuntu 中启用 root 帐号的话, ...
- [Go] Cookie 使用简介
Golang 的 Cookie web 开发免不了要和 cookie 打交道.Go 的 http 库也提供了 cookie 的相关操作. type Cookie struct { Name strin ...
- Linux Shell脚本入门--wc命令
wc 统计文件里面有多少单词,多少行,多少字符. wc语法 [root@www ~]# wc [-lwm] 选项与参数: -l :仅列出行: -w :仅列出多少字(英文单字): -m :多少字符: 默 ...
- deeplearningbook-chinese
https://exacity.github.io/deeplearningbook-chinese/
- ICE概述
网络通信引擎(Internet Communications Engine, Ice)是由ZeroC的分布式系统开发专家实现的一种高性能.面向对象的中间件平台.它号称标准统一,开源,跨平台,跨语言,分 ...
- 得到WAV文件的长度
long getVideoLength (char *fileName){ MCI_OPEN_PARMS mciOpenParms; MCI_STATUS_PARMS mciStatusPar ...