Advertisement
DulcetAirman

encodeArray

Sep 24th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1.   public static int[] encodeArray(final int i) {
  2.     return Integer.toString(i).chars().map(x -> x - '0').flatMap(digit -> {
  3.       if (digit < 0) return IntStream.of(-1); // sign: '-'
  4.       final Builder builder = IntStream.builder();
  5.       for (int x = 0; x < digit; x++) builder.accept(0);
  6.       builder.accept(1);
  7.       return builder.build();
  8.     }).toArray();
  9.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement