My solution.

master
Rohweini 5 years ago
parent c3966f3397
commit d49e0b9453

@ -1,16 +1,41 @@
import java.util.*;
import java.io.*;
import java.math.*;
class Solution {
public static void main( String[] args ) {
Scanner in = new Scanner( System.in );
// read values with in.next...() methods
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// read values with in.next...() methods
int iterations = in.nextInt();
// code your solution here
String sequence = getSequence(iterations, new StringBuilder("1"));
// code your solution here
// Write result with System.out.println()
System.out.println(sequence);
}
// Write result with System.out.println()
System.out.println( "value" );
}
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…
Cancel
Save