import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; class Solution { public static String numberOfNumbers(int value) { String delimiter = getDelimiterFor(value); return IntStream.rangeClosed(0, Math.abs(value)) .mapToObj(Solution::repeatByItself) .filter(Solution::notBlank) .collect(Collectors.joining(delimiter)); } private static String getDelimiterFor(int value){ return value > 0 ? "-" : "+"; } private static String repeatByItself(int i){ return String.valueOf(i).repeat(i); } private static boolean notBlank(String s){ return !s.isBlank(); } }
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- import java.util.stream.Stream;
- class Solution {
public static String numberOfNumbers(final int value) {if (value == 0) {return "";}final String delimiter = value > 0 ? "-" : "+";return IntStream.rangeClosed(1, Math.abs(value)).mapToObj(n -> new String(new char[n]).replace("\0", String.valueOf(n)))- public static String numberOfNumbers(int value) {
- String delimiter = getDelimiterFor(value);
- return IntStream.rangeClosed(0, Math.abs(value))
- .mapToObj(Solution::repeatByItself)
- .filter(Solution::notBlank)
- .collect(Collectors.joining(delimiter));
- }
- private static String getDelimiterFor(int value){
- return value > 0 ? "-" : "+";
- }
- private static String repeatByItself(int i){
- return String.valueOf(i).repeat(i);
- }
- private static boolean notBlank(String s){
- return !s.isBlank();
- }
- }