[
array
hash table
]
BinarySearch 0664 Missing Numbers From 1 to N
Problem statement
https://binarysearch.com/problems/Missing-Numbers-From-1-to-N/
Solution
Equal to Leetcode 0448 Find All Numbers Disappeared in an Array.
Complexity
Time complexity is O(n)
, additional space is O(1)
.
Code
class Solution:
def solve(self, nums):
n = len(nums)
for num in nums:
nums[(num-1) % n] += n
return [i+1 for i in range(n) if nums[i] <= n]