Title description:
A "zero-zero integer" is a positive integer that does not contain any zeros in the decimal representation.
Given an integer n, please return a list of two integers [A, B], satisfying:
- A and B are both zero-zero integers
- A + B = n
The problem data guarantees that there is at least one effective solution.
If there are multiple valid solutions, you can return to any one of them.
prompt:
- 2 <= n <= 10^4
Example 1:
Input: n = 2
Output: [1,1]
Explanation: A = 1, B = 1. A + B = n and the decimal representations of A and B do not contain any 0.
Example 2:
Input: n = 11
Output: [2,9]
Example 3:
Input: n = 10000
Output: [1,9999]
Example 4:
Input: n = 69
Output: [1,68]
Example 5:
Input: n = 1010
Output: [11,999]
code show as below:
class Solution {
public int[] getNoZeroIntegers(int n) {
int[] arr = new int[2];
for (int i = 1; i <= n; i++) {
String s1 = String.valueOf(i);
String s2 = String.valueOf(n - i);
int a = s1.indexOf('0');
int b = s2.indexOf('0');
if (a == -1 && b == -1) {
arr[0] = i;
arr[1] = n - i;
break;
}
}
return arr;
}
}
Results of the: