Convert Integer to the Sum of Two No-Zero Integers
Description
Approach
Implementation
Java
class Solution {
private boolean hasNoZero(int num) {
return !String.valueOf(num)
.chars()
.mapToObj(ch -> (char)ch)
.anyMatch(ch -> ch == '0');
}
public int[] getNoZeroIntegers(int n) {
return java.util.stream.IntStream
.rangeClosed(1, n-1)
.filter(a -> {
int b = n - a;
return hasNoZero(a) && hasNoZero(b);
})
.mapToObj(a -> new int[]{a, n-a})
.findFirst()
.orElse(new int[]{});
}
}C++
Rust
Go
Complexity
Last updated