Skip to content

Commit ca9c2c7

Browse files
authored
Merge pull request #1290 from ivan1016017/june02
plus one added
2 parents fe31d81 + 2be6c79 commit ca9c2c7

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/my_project/interviews/top_150_questions_round_16/palindrome.py renamed to src/my_project/interviews/top_150_questions_round_16/palindrome_number.py

File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def plusOne(self, digits: List[int]) -> List[int]:
6+
7+
len_digits = len(digits)
8+
9+
for i in range(len_digits-1,-1,-1):
10+
11+
if digits[i] != 9:
12+
digits[i] += 1
13+
break
14+
else:
15+
digits[i] = 0
16+
17+
if digits[0] == 0:
18+
return [1] + digits
19+
else:
20+
return digits

tests/test_150_questions_round_16/test_palindrome_round_16.py renamed to tests/test_150_questions_round_16/test_palindrome_number_round_16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from src.my_project.interviews.top_150_questions_round_16\
3-
.palindrome import Solution
3+
.palindrome_number import Solution
44

55
class PalindromeNumberTestCase(unittest.TestCase):
66

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_16\
3+
.plus_one import Solution
4+
5+
class PlusOneTestCase(unittest.TestCase):
6+
7+
def test_leading_one(self):
8+
solution = Solution()
9+
output = solution.plusOne(digits=[9])
10+
target = [1, 0]
11+
for k, v in enumerate(target):
12+
self.assertEqual(v, output[k])
13+
14+
def test_no_leading_one(self):
15+
solution = Solution()
16+
output = solution.plusOne(digits=[1, 2])
17+
target = [1, 3]
18+
for k, v in enumerate(target):
19+
self.assertEqual(v, output[k])

0 commit comments

Comments
 (0)