String

Description:

个人觉得这个题意实在是反人类!!!

在此说明一下题意:

my Solution:

public class Solution {
public String countAndSay(int n) {
StringBuffer sb = new StringBuffer("1");
for (int i = 1; i < n; i++) {
StringBuffer next = new StringBuffer();
int count = 1;
for (int j = 0; j < sb.length(); j++) {
if (j+1 < sb.length() && sb.charAt(j) == sb.charAt(j+1)) {
count++;
} else {
next.append(count).append(sb.charAt(j));
count = 1;
}
}
sb = next;
}
return sb.toString();
}
}
04-25 07:26
查看更多