#1317
Easy Algorithms Convert integer to the sum of two no zero integers
Math
59.1% acceptance
Feb 25, 2026
862
371
No-Zero integer is a positive integer that does not contain any 0 in its decimal representation.
Given an integer n, return a list of two integers [a, b] where:
a and b are No-Zero integers.
a + b = n
The test cases are generated so that there is at least one valid solution. If there are many valid solutions, you can return any of them.
Solution
Rust
Time O(2^n)
Space O(n)
impl Solution {
pub fn get_no_zero_integers(n: i32) -> Vec<i32> {
fn has_zero(mut x: i32) -> bool {
while x > 0 {
if x % 10 == 0 { return true; }
x /= 10;
}
false
}
for a in 1..n {
let b = n - a;
if !has_zero(a) && !has_zero(b) {
return vec![a, b];
}
}
unreachable!()
}
}