Given an integer n. No-Zero integer is a positive integer
which doesn't contain any 0 in its decimal representation.
Return a list of two integers [A, B] where:
A and B are No-Zero integers.
A + B = n
It's guarateed that there is at least one valid solution.
If there are many valid solutions you can return any of them.
Example 1:
Input: n =2
Output:[1,1]
Explanation: A =1, B =1. A + B = n and both A and B don't contain any 0 in their decimal representation.
Example 5:
Input: n =1010
Output:[11,999]
二、题解
(1) 暴力枚举(字符串处理)
publicint[]getNoZeroIntegers(int n){for(int i =1; i < n; i++){//if((i+"").indexOf("0") < 0 && ((n-i) + "").indexOf("0") < 0)if(!String.valueOf(i).contains("0")&&!String.valueOf(n-i).contains("0"))returnnewint[]{i, n-i};}returnnewint[2];}
(2) 数位计算
publicint[]getNoZeroIntegers(int n){for(int i =1; i < n; i++)if(isValid(i)&&isValid(n-i))returnnewint[]{i, n-i};returnnewint[2];}privatebooleanisValid(int n){while(n !=0){if(n %10==0)returnfalse;
n /=10;}returntrue;}