448. Find All Numbers Disappeared in an Array
442. Find All Duplicates in an Array
两道非常相似的题目
都是使用nums[nums[i]-1] = -nums[nums[i]-1]
,前提是这个数组是[1,n]
原理是数组中的下标是[0,n-1],然后通过上述的转换,即访问过得数字变为了负数,其中减一的原因是数组和下标相差1
448找重复
|
|
442找没有出现的
|
|
448. Find All Numbers Disappeared in an Array
442. Find All Duplicates in an Array
两道非常相似的题目
都是使用nums[nums[i]-1] = -nums[nums[i]-1]
,前提是这个数组是[1,n]
原理是数组中的下标是[0,n-1],然后通过上述的转换,即访问过得数字变为了负数,其中减一的原因是数组和下标相差1
448找重复
|
|
442找没有出现的
|
|
近期评论