count and say

####

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Solution{
public String countAndSay(int n){
if(n < 1)
return "";
String result = "1";
while(n > 1){
String temp = ""; //每求一个新的n,都得是从头开始
char[] Array = result.toCharArray();
for(int i = 0 ; i < Array.length ; i++){
int count = 1;
while(i+1 < Array.length && Array[i] == Array[i+1]){
count++;
i++;
}
temp = temp + count + Array[i]; //利用String的“+”特性
result = temp;
}
n--;
}
return result;
}
}