Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-08-20_22-23-53.png
50.1 KB
#medium
#N38. Count and Say
problem link
#solution
class Solution {
public String countAndSay(int n) {
StringBuilder sb = new StringBuilder("1");
StringBuilder temp = new StringBuilder();
int sikl=2, count;
while(sikl++<=n){
count=1;
for(int i=1; i<sb.length(); i++){
if(sb.charAt(i-1)==sb.charAt(i)) count++;
else{
temp.append(count).append(sb.charAt(i-1));
count = 1;
}
}
temp.append(count).append(sb.charAt(sb.length()-1));
sb=temp;
temp = new StringBuilder();
}
return sb.toString();
}
}