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 2bc5898 commit eb3c7a8Copy full SHA for eb3c7a8
solution/0038.Count and Say/Solution.java
@@ -0,0 +1,23 @@
1
+class Solution {
2
+ public String countAndSay(int n) {
3
+ String one = "1";
4
+ while (n > 1) {
5
+ one = say(one);
6
+ n--;
7
+ }
8
+ return one;
9
10
+
11
+ private String say(String las) {
12
+ StringBuilder sBuilder = new StringBuilder();
13
+ int l = 1;
14
+ for (int i = 0; i < las.length(); i++) {
15
+ if (i < las.length() - 1 && las.charAt(i) == las.charAt(i + 1)) l++;
16
+ else {
17
+ sBuilder.append(l).append(las.charAt(i));
18
+ l = 1;
19
20
21
+ return sBuilder.toString();
22
23
+}
0 commit comments