import java.util.stream.Collectors; import java.util.stream.IntStream; class Solution { public static String numberOfNumbers(final int value) { return IntStream.rangeClosed(1, Math.abs(value)) .mapToObj(n -> new String(new char[n]).replace("\0", String.valueOf(n))) .collect(Collectors.joining(value > 0 ? "-" : "+")); } }
- 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)))
.collect(Collectors.joining(delimiter));- .collect(Collectors.joining(value > 0 ? "-" : "+"));
- }
- }