- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem38.java
More file actions
Latest commit
34 lines (33 loc) · 958 Bytes
/
Copy pathProblem38.java
File metadata and controls
34 lines (33 loc) · 958 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
26
27
28
29
30
31
32
33
34
classProblem38 {
publicstaticvoidmain(String[] args) {
Problem38p = newProblem38();
System.out.println(p.countAndSay(4));
}
publicStringcountAndSay(intn) {
Stringstr = "1";
if (n <= 1) {
returnstr;
}
for (inti = 1; i < n; i++) {
charpre = str.charAt(0);
StringBufferbuffer = newStringBuffer();
intcount = 1;
charc = pre;
for (intj = 1; j < str.length(); j++) {
c = str.charAt(j);
if (c != pre) {
buffer.append(count);
buffer.append(pre);
count = 0;
}
count++;
pre = c;
}
buffer.append(count);
buffer.append(c);
str = buffer.toString();
//System.out.println(i+"--"+str);
}
returnstr;
}
}