Skip to content

Commit 5af8e69

Browse files
committed
D. J.:
- Added the leetcode problem and solution for 2154
1 parent 9458d68 commit 5af8e69

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
- [1935 Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type/description/)
298298
- [1964 Find the Longest Valid Obstacle Course at Each Position](https://leetcode.com/problems/find-the-longest-valid-obstacle-course-at-each-position/description/)
299299
- [2140 Solving Questions With Brainpower](https://leetcode.com/problems/solving-questions-with-brainpower/description/)
300+
- [2154 Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two/description/)
300301
- [2215 Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays/description/)
301302
- [2353 Design a Food Rating System](https://leetcode.com/problems/design-a-food-rating-system/description/)
302303
- [2390 Removing Stars From a String](https://leetcode.com/problems/removing-stars-from-a-string/description/)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""Base class for all LeetCode Problems."""
6+
7+
def findFinalValue(self, nums: List[int], original: int) -> int:
8+
"""
9+
You are given an array of integers nums. You are also given an integer original
10+
which is the first number that needs to be searched for in nums.
11+
12+
You then do the following steps:
13+
1. If original is found in nums, multiply it by two (i.e., set original = 2 *
14+
original).
15+
2. Otherwise, stop the process.
16+
3. Repeat this process with the new number as long as you keep finding the
17+
number.
18+
19+
Return the final value of original.
20+
"""
21+
# Time Complexity: O(1)
22+
# Space Complexity: O(n)
23+
nums = set(nums)
24+
while original in nums:
25+
original *= 2
26+
return original
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import List
2+
3+
import pytest
4+
5+
from awesome_python_leetcode._2154_keep_multiplying_found_values_by_two import Solution
6+
7+
8+
@pytest.mark.parametrize(
9+
argnames=["nums", "original", "expected"],
10+
argvalues=[
11+
([5, 3, 6, 1, 12], 3, 24),
12+
([2, 7, 9], 4, 4),
13+
],
14+
)
15+
def test_func(nums: List[int], original: int, expected: int):
16+
"""Tests the solution of a LeetCode problem."""
17+
final_value = Solution().findFinalValue(nums, original)
18+
assert final_value == expected

0 commit comments

Comments
 (0)