网页学习体会

  • 首页
  • 个人博客
您的位置: 首页  >  IT文章  >  LeetCode: Find All Duplicates in an Array

LeetCode: Find All Duplicates in an Array

分类: IT文章 • 2023-03-31 11:51:51

这里只能出现2次或者1次,不可能有3次或者3次以上

 1 public class Solution {
 2     public List<Integer> findDuplicates(int[] nums) {
 3         List<Integer> ans = new ArrayList<Integer>();
 4         for (int i = 0; i < nums.length; i++) {
 5             int val = Math.abs(nums[i]) - 1;
 6             if (nums[val] < 0) ans.add(val+1);
 7             nums[val] = -nums[val];
 8         }
 9         return ans;
10     }
11 }

相关推荐

  • LeetCode 26 Remove Duplicates from Sorted Array
  • LeetCode T1095.Find in Mountain Array/山脉数组中查找目标值
  • Remove Duplicates from Sorted Array @leetcode
  • leetcode-Find Minimum in Rotated Sorted Array II
  • Leetcode 26. Remove Duplicates from Sorted Array
  • LeetCode 448. Find All Numbers Disappeared in an Array
  • 448. Find All Numbers Disappeared in an Array&&645. Set Mismatch 题目: 思路: 代码:
  • Java for LeetCode 026 Remove Duplicates from Sorted Array
  • leetcode — remove-duplicates-from-sorted-array
  • LeetCode Find Minimum in Rotated Sorted Array
  • LeetCode: Convert BST to Greater Tree
  • C# 开源仪表盘库—Agauge App
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 网页学习体会    备案号:   粤ICP备20002247号