From e40a826d24f73cfd4b8b474efa29842fe6fa31ab Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 7 Jul 2025 04:27:28 -0600 Subject: [PATCH] adding algo --- .../top_150_questions_round_17/plus_one.py | 21 +++++++++++++++++++ .../test_plus_one_round_17.py | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_17/plus_one.py create mode 100644 tests/test_150_questions_round_17/test_plus_one_round_17.py diff --git a/src/my_project/interviews/top_150_questions_round_17/plus_one.py b/src/my_project/interviews/top_150_questions_round_17/plus_one.py new file mode 100644 index 00000000..56906e1b --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_17/plus_one.py @@ -0,0 +1,21 @@ +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_17/test_plus_one_round_17.py b/tests/test_150_questions_round_17/test_plus_one_round_17.py new file mode 100644 index 00000000..f4d641e5 --- /dev/null +++ b/tests/test_150_questions_round_17/test_plus_one_round_17.py @@ -0,0 +1,19 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_17\ +.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