Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Count and Say
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static String countAndSay(int n){ if(n == 1){ return "1"; } String s = countAndSay(n-1); StringBuilder sb = new StringBuilder(); char say = s.charAt(0); int count = 1; for(int i = 1;i<s.length();i++){ char c = s.charAt(i); if(c==say){ count++; } else{ sb.append(count).append(say); say = c; count = 1; } } sb.append(count).append(say); return sb.toString(); } public static void main(String args[]) { System.out.println("Hello, World!"); System.out.println(countAndSay(5)); } }
run
|
edit
|
history
|
help
0
Problem Name: single_digit
Elevator Sim
luas
Lexisort
ekse
Java Lambda Expression Sample
bubble sort
Preference List
"Naive" recursion vs. Dynamic Programming
LinearSearch