Time Complexity: O(n * cur.length()). Space: O(cur.length()). AC Java: 1classSolution {2publicString countAndSay(intn) {3if(n <= 0){4return"";5}67StringBuilder sb =newStringBuilder("1");8for(intk = 1; k<n; k++){9String pre =sb.toString();10sb =newStringBuilder();11i...
1个1 2个1 1个2,1个1 1个1,1个2,2个1 3个1,2个2,1个1 依次类推 题目很简单,但是为了得到较好的结果,还是纠结了一段时间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 publicclasscountAndSay { publicString countAndSay(intn) { String num ="1"; for(intm ...
class Solution: """ @param n: the nth @return: the nth sequence """ def countAndSay(self, n): # write your code here result = "1" for i in range(n - 1): # find next result nextResult = "" count = 1 for j in range(len(result)): if j == len(result) - 1 or result...
代码(Java): 代码语言:javascript 复制 publicclassSolution{publicStringcountAndSay(int n){if(n==0)return"";int[]resultArray=newint[10000];resultArray[0]=1;int index=1;for(int i=1;i<n;i++){int last=resultArray[0];int lastSame=0;int[]tempArray=newint[10000];int num=0;int j=0;...
public String countAndSay(intn){// 递归尽头返回空或者1if(n==0) return"";if(n==1) return"1";// 计算出上一个字符串String s = countAndSay(n- 1); StringBuilder sb =newStringBuilder();// 通过记录上次的字符来判断是否重复charlast = s.charAt(0);intcnt =1;for(inti =1; i < s.le...
Q38 Count and Say The count-and-say sequence is the sequence of integers with the first five terms as following: 代码语言:javascript 复制 1.12.113.214.12115.111221 代码语言:javascript 复制 1is read offas"one 1"or11.11is read offas"two 1s"or21.21is read offas"one 2, then one 1"or1211...
Whitespace Ignore whitespace Split Unified 72 changes: 0 additions & 72 deletions 72 interview_questions/Java/LC_38_count_and_say.java Load diff This file was deleted. 0 comments on commit 10fcf2a Please sign in to comment. Footer...
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 term of the count-and-say sequence. Note:Each term of the sequence of integers will be represented as a string. ...
2.Java的内存分配,垃圾回收 3.Java的堆栈是什么,有什么特点 4.Hashmap的原理和特点 5.Hashmap存储100万数据,有什么优化的想法 6.说一下实习做的事情,困难点是什么,你怎么解决的 7.做题:lc38 Count and Say 2.29 二面 + 主管面 连着一起面了
You could solve this problem by using a method of String that allows you to decide whether a certain String (say "e") appears in another String (say "It's Owl Stretching Time"). All methods of String can be found in the API.