I convert nums to a set for O(1) lookup. Then I repeatedly check if original is in the set; if it is, I double it. If not, I stop and return the final value.
class Solution:
def findFinalValue(self, nums: List[int], original: int) -> int:
s = set(nums)
while original in s:
original *= 2
return original- Time: O(n)
- Space: O(n)