forked from dharmanshu1921/Java
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountAndSay.java
More file actions
Latest commit
30 lines (29 loc) · 709 Bytes
/
Copy pathCountAndSay.java
File metadata and controls
30 lines (29 loc) · 709 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
classCountAndSay {
publicStringcountIdx(Strings){
StringBuildersb = newStringBuilder();
charc = s.charAt(0);
intcount = 1;
for(inti = 1; i < s.length(); i++){
if(s.charAt(i) == c){
count++;
}
else
{
sb.append(count);
sb.append(c);
c = s.charAt(i);
count = 1;
}
}
sb.append(count);
sb.append(c);
returnsb.toString();
}
publicStringcountAndSay(intn) {
Strings = "1";
for(inti = 1; i < n; i++){
s = countIdx(s);
}
returns;
}
}