由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教leetcode上的count and say
相关主题
请教两个算法题leetcode的count and say
问下LeetCode上的题目:count and sayG电面题 + 求祝福
一道面试题(integer to binary string)问一道老题
Amazon first phone interview这题怎么做?
请教 怎样存下这个string这题也可以DP 解吧?
storm8 online code给跪了求OJ container with most water O(n)解法
这题应该用bucket sort还是counting sort这题有啥好方法吗?
这题怎么做?这题怎么做?
相关话题的讨论汇总
话题: string话题: integer话题: start话题: 1211话题: count
进入JobHunting版参与讨论
1 (共1页)
m******8
发帖数: 41
1
leetcode上的count and say这题,是一个什么思路?我在另一个帖子上有看到这题的
代码,但是我水平较低,主要想请教一下这题是什么思路。
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.
我看到的帖子是在,http://www.mitbbs.com/article_t/JobHunting/32147785.html
谢谢
d**e
发帖数: 6098
2
就是连续数字的个数

follows:

【在 m******8 的大作中提到】
: leetcode上的count and say这题,是一个什么思路?我在另一个帖子上有看到这题的
: 代码,但是我水平较低,主要想请教一下这题是什么思路。
: 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.

l****c
发帖数: 782
3
记得这是我练的第一道题,
就是从1往下做就是了吧,
lz先把题理解了,理解了做应该不难。
1
11
21
1211
111221
312211
13112221
。。。。。
I***C
发帖数: 765
4
1 "1" 1个1=〉11 (相当于把里面的汉字‘个’去掉以后省的数串)
2 "11" 2个1=〉21
3 "21" 1个2,1个1=〉1211
4 "1211" 1个1,1个2,2个1 =〉111221
5 "111221" 3个1,2个2,1个1 =〉312211
6 "312211"
7 "13112221"
8 "1113213211"
9 "31131211131221"
10 "13211311123113112211"
11 "11131221133112132113212221"
12 "3113112221232112111312211312113211"
13 "1321132132111213122112311311222113111221131221"
14 "11131221131211131231121113112221121321132132211331222113112211"

follows:

【在 m******8 的大作中提到】
: leetcode上的count and say这题,是一个什么思路?我在另一个帖子上有看到这题的
: 代码,但是我水平较低,主要想请教一下这题是什么思路。
: 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.

a********y
发帖数: 1262
5
private static java.util.Hashtable cache = new java.util.
Hashtable();
public String countAndSay(int n)
{
// Start typing your Java solution below
// DO NOT write main() function
Object result = cache.get(new Integer(n));
if(result != null)
{
return (String)result;
}
if(n == 1)
{
cache.put(new Integer(1), "1");
return "1";
}
else
{
String str = countAndSay(n-1);
String re = sayOneString(str);
cache.put(new Integer(n), re);
return re;
}
}
public static String sayOneString(String str)
{
int start = 0;
int end = 1;
StringBuffer sb = new StringBuffer();
while(start < str.length())
{
while(end < str.length() && str.charAt(end) == str.charAt(start
))
{
end ++;
}
sb.append(""+(end-start)+str.charAt(start));
start = end;
end = start+1;
}
return sb.toString();
}

follows:

【在 m******8 的大作中提到】
: leetcode上的count and say这题,是一个什么思路?我在另一个帖子上有看到这题的
: 代码,但是我水平较低,主要想请教一下这题是什么思路。
: 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.

1 (共1页)
进入JobHunting版参与讨论
相关主题
这题怎么做?请教 怎样存下这个string
发一道G家的onsite题及教训,顺便求linkedin和twitter内推storm8 online code给跪了
find medium number in stream 这题怎么作这题应该用bucket sort还是counting sort
Integer to English Words这题的出现频率真的很高吗?这题怎么做?
请教两个算法题leetcode的count and say
问下LeetCode上的题目:count and sayG电面题 + 求祝福
一道面试题(integer to binary string)问一道老题
Amazon first phone interview这题怎么做?
相关话题的讨论汇总
话题: string话题: integer话题: start话题: 1211话题: count