Skip to content

Commit 65c7b11

Browse files
committedJan 13, 2020
Add solution #1317
1 parent bc8733f commit 65c7b11

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 1317. Convert Integer to the Sum of Two No-Zero Integers
3+
* https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer n. No-Zero integer is a positive integer which
7+
* doesn't contain any 0 in its decimal representation.
8+
*
9+
* Return a list of two integers [A, B] where:
10+
*
11+
* - A and B are No-Zero integers.
12+
* - A + B = n
13+
*
14+
* It's guarateed that there is at least one valid solution.
15+
* If there are many valid solutions you can return any of them.
16+
*/
17+
18+
/**
19+
* @param {number} n
20+
* @return {number[]}
21+
*/
22+
var getNoZeroIntegers = function(n) {
23+
const hasNoZero = n => String(n).indexOf('0') === -1;
24+
for (let i = n; i; --i) {
25+
if (hasNoZero(i) && hasNoZero(n - i)) {
26+
return [i, n - i];
27+
}
28+
}
29+
};

0 commit comments

Comments
 (0)