Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements that appear twice in this array.
Example
Example1
Example2
Challenge
Could you do it without extra space and in O(n) runtime?
分析
把当前数abs(x)-1作为Index, nums[index] flop. 如果当前数字已经是负数,说明index+1已经出现过
Last updated
Was this helpful?