Leetcode——442. 数组中重复的数据(Java)
代码如下
class Solution {
public List<Integer> findDuplicates(int[] nums) {
List<Integer> rs = new ArrayList<>();
for(int i = 0; i < nums.length; i ++){
if(nums[Math.abs(nums[i])-1] < 0){
rs.add(Math.abs(nums[i]));
}else{
nums[Math.abs(nums[i])-1] *= -1;
}
}
return rs;
}
}