[LeetCode] Convert Integer to the Sum of Two No-Zero Integers

1317. Convert Integer to the Sum of Two No-Zero Integers

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
vector<int> getNoZeroIntegers(int n) {
auto ok = [](int n) {
while(n) {
if(n % 10 == 0) return false;
n /= 10;
}
return true;
};
for(int i = 1; i < n; i++) {
if(ok(i) and ok(n-i)) return {i,n-i};
}
return {};
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/09/09/PS/LeetCode/convert-integer-to-the-sum-of-two-no-zero-integers/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.