448. Find All Numbers Disappeared in an Array
Input:
[4,3,2,7,8,2,3,1]
Output:
[5,6]class Solution(object):
def findDisappearedNumbers(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
# negating the number indexed by the value
for i in range(len(nums)):
idx = abs(nums[i]) - 1
if(nums[idx] > 0):
nums[idx] = -nums[idx]
res = []
for i in range(len(nums)):
if(nums[i] > 0):
res.append(i + 1)
return resLast updated
Was this helpful?