Leetcode——442. 数组中重复的数据(Java)
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;   
    }
}

相关文章:

  • 2021-05-28
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2021-12-01
  • 2021-09-21
  • 2021-12-09
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案