38. 报数
作者:
_道友请留步_ | 来源:发表于
2018-05-04 11:29 被阅读0次class Solution {
public String countAndSay(int n) {
if(n == 1){
return "1";
} else {
StringBuilder sb = new StringBuilder();
String string = countAndSay(n-1);
int i = 0;
while(i < string.length()){
char c = string.charAt(i);
int count = 0;
for(int offset = i; offset < string.length(); offset++){
if(string.charAt(offset) == c){
count++;
}else{
break;
}
}
i += count;
sb.append(count).append(c);
}
return sb.toString();
}
}
}
本文标题:38. 报数
本文链接:https://www.haomeiwen.com/subject/wehdrftx.html
网友评论