My solution.

master
Rohweini 4 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
// code your solution here
// Write result with System.out.println()
System.out.println( "value" );
}
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"));
// 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…
Cancel
Save