We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c234e29 commit 4f7f0bdCopy full SHA for 4f7f0bd
EASY/src/easy/CountandSay.java
@@ -0,0 +1,28 @@
1
+package easy;
2
+
3
+public class CountandSay {
4
5
+ public String countAndSay(int n) {
6
+ StringBuilder curr = new StringBuilder("1");
7
+ StringBuilder prev;
8
+ int count;
9
+ char say;
10
+ for(int i = 1; i < n; i++){
11
+ prev = curr;
12
+ curr = new StringBuilder();
13
+ count = 1;
14
+ say = prev.charAt(0);
15
16
+ for(int j = 1, len = prev.length(); j < len; j++){
17
+ if(prev.charAt(j) != say){
18
+ curr.append(count).append(say);
19
20
+ say = prev.charAt(j);
21
+ } else count++;
22
+ }
23
24
25
+ return curr.toString();
26
27
28
+}
0 commit comments