Skip to content

Commit fdb7648

Browse files
committed
D. J.:
- Added the leetcode problem and solution for 1317
1 parent 4c6d637 commit fdb7648

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
- [1218 Longest Arithmetic Subsequence of Given Difference](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference/description/)
284284
- [1304 Find N Unique Integers Sum up to Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/description/)
285285
- [1312 Minimum Insertion Steps to Make a String Palindrome](https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/description/)
286+
- [1317 Convert Integer to the Sum of Two No-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/description/)
286287
- [1329 Sort the Matrix Diagonally](https://leetcode.com/problems/sort-the-matrix-diagonally/description/)
287288
- [1456 Maximum Number of Vowels in a Substring of Given Length](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/description/)
288289
- [1534 Count Good Triplets](https://leetcode.com/problems/count-good-triplets/description/)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""Base class for all LeetCode Problems."""
6+
7+
def hasZeros(self, n: int) -> bool:
8+
"""Check if the integer n has any zeros in its decimal representation."""
9+
while n != 0:
10+
digit = n % 10
11+
if digit == 0:
12+
return True
13+
n = n // 10
14+
return False
15+
16+
def getNoZeroIntegers(self, n: int) -> List[int]:
17+
"""
18+
No-Zero integer is a positive integer that does not contain any 0 in its decimal
19+
representation.
20+
21+
Given an integer n, return a list of two integers [a, b] where:
22+
- a and b are No-Zero integers.
23+
- a + b = n
24+
25+
The test cases are generated so that there is at least one valid solution. If
26+
there are many valid solutions, you can return any of them.
27+
"""
28+
num1 = n // 2 + 1 if n % 2 else n // 2
29+
num2 = n // 2
30+
while self.hasZeros(num1) or self.hasZeros(num2):
31+
num1 -= 1
32+
num2 += 1
33+
return [num1, num2]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from typing import List
2+
3+
import pytest
4+
5+
from awesome_python_leetcode._1317_convert_integer_to_the_sum_of_two_no_zero_integers import ( # noqa: E501
6+
Solution,
7+
)
8+
9+
10+
@pytest.mark.parametrize(
11+
argnames=["n", "expected"],
12+
argvalues=[
13+
(2, [1, 1]),
14+
(11, [6, 5]),
15+
(1010, [499, 511]),
16+
(19, [8, 11]),
17+
(2081, [969, 1112]),
18+
],
19+
)
20+
def test_func(n: int, expected: List[int]):
21+
"""Tests the solution of a LeetCode problem."""
22+
zero_integers = Solution().getNoZeroIntegers(n)
23+
assert zero_integers == expected

0 commit comments

Comments
 (0)