- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCountAndSay.java
More file actions
Latest commit
25 lines (25 loc) · 682 Bytes
/
Copy pathCountAndSay.java
File metadata and controls
25 lines (25 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
publicclassSolution {
publicStringcountAndSay(intn) {
Stringresult = "1";
StringBuffernewString = newStringBuffer("");
inti = 1;
while(i<n) {
chartmp = result.charAt(0);
intnum = 1;
for(intk=1;k<result.length();k++) {
if(result.charAt(k)==tmp) {
num++;
continue;
}
newString.append(Integer.toString(num) + tmp);
tmp = result.charAt(k);
num = 1;
}
newString.append(Integer.toString(num) + tmp);
result = newString.toString();
newString.setLength(0);
i++;
}
returnresult;
}
}