diff --git a/src/my_project/interviews/top_150_questions_round_16/palindrome.py b/src/my_project/interviews/top_150_questions_round_16/palindrome_number.py similarity index 100% rename from src/my_project/interviews/top_150_questions_round_16/palindrome.py rename to src/my_project/interviews/top_150_questions_round_16/palindrome_number.py diff --git a/src/my_project/interviews/top_150_questions_round_16/plus_one.py b/src/my_project/interviews/top_150_questions_round_16/plus_one.py new file mode 100644 index 00000000..daed75a1 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_16/plus_one.py @@ -0,0 +1,20 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def plusOne(self, digits: List[int]) -> List[int]: + + len_digits = len(digits) + + for i in range(len_digits-1,-1,-1): + + if digits[i] != 9: + digits[i] += 1 + break + else: + digits[i] = 0 + + if digits[0] == 0: + return [1] + digits + else: + return digits \ No newline at end of file diff --git a/tests/test_150_questions_round_16/test_palindrome_round_16.py b/tests/test_150_questions_round_16/test_palindrome_number_round_16.py similarity index 92% rename from tests/test_150_questions_round_16/test_palindrome_round_16.py rename to tests/test_150_questions_round_16/test_palindrome_number_round_16.py index 46345b36..468bcd77 100644 --- a/tests/test_150_questions_round_16/test_palindrome_round_16.py +++ b/tests/test_150_questions_round_16/test_palindrome_number_round_16.py @@ -1,6 +1,6 @@ import unittest from src.my_project.interviews.top_150_questions_round_16\ -.palindrome import Solution +.palindrome_number import Solution class PalindromeNumberTestCase(unittest.TestCase): diff --git a/tests/test_150_questions_round_16/test_plus_one_round_16.py b/tests/test_150_questions_round_16/test_plus_one_round_16.py new file mode 100644 index 00000000..e0fe76b4 --- /dev/null +++ b/tests/test_150_questions_round_16/test_plus_one_round_16.py @@ -0,0 +1,19 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_16\ +.plus_one import Solution + +class PlusOneTestCase(unittest.TestCase): + + def test_leading_one(self): + solution = Solution() + output = solution.plusOne(digits=[9]) + target = [1, 0] + for k, v in enumerate(target): + self.assertEqual(v, output[k]) + + def test_no_leading_one(self): + solution = Solution() + output = solution.plusOne(digits=[1, 2]) + target = [1, 3] + for k, v in enumerate(target): + self.assertEqual(v, output[k]) \ No newline at end of file