2154. Keep Multiplying Found Values by Two
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 71% Topics: Array, Hash Table, Sorting, Simulation
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(n)
# hash table
class Solution(object):
def findFinalValue(self, nums, original):
"""
:type nums: List[int]
:type original: int
:rtype: int
"""
lookup = set(nums)
while original in lookup:
original *= 2
return original
Solution from kamyu104/LeetCode-Solutions · MIT