forked from code-clash/look-and-say
My solution.
parent
c3966f3397
commit
d49e0b9453
@ -1,16 +1,41 @@
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
|
||||||
import java.math.*;
|
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
|
|
||||||
public static void main( String[] args ) {
|
public static void main(String[] args) {
|
||||||
Scanner in = new Scanner( System.in );
|
Scanner in = new Scanner(System.in);
|
||||||
// read values with in.next...() methods
|
// read values with in.next...() methods
|
||||||
|
int iterations = in.nextInt();
|
||||||
// code your solution here
|
// code your solution here
|
||||||
|
String sequence = getSequence(iterations, new StringBuilder("1"));
|
||||||
// Write result with System.out.println()
|
|
||||||
System.out.println( "value" );
|
// Write result with System.out.println()
|
||||||
}
|
System.out.println(sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSequence(int input, StringBuilder previousSequence) {
|
||||||
|
if (input == 0) {
|
||||||
|
return previousSequence.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
StringBuilder sequence = new StringBuilder();
|
||||||
|
char currentCharacter = previousSequence.charAt(0);
|
||||||
|
|
||||||
|
for (int i = 0; i < previousSequence.length(); i++) {
|
||||||
|
char character = previousSequence.charAt(i);
|
||||||
|
if (character != currentCharacter) {
|
||||||
|
sequence.append(counter) ; //first add the count
|
||||||
|
sequence.append(currentCharacter); //count follwed by the actual number
|
||||||
|
counter = 0;
|
||||||
|
|
||||||
|
currentCharacter = character;
|
||||||
|
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
sequence.append(counter) ; //first add the count
|
||||||
|
sequence.append(currentCharacter); //count follwed by the actual number
|
||||||
|
return getSequence(input - 1, sequence);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue