题意:在数组元素为1-n的数组中找到出现两次的数

思路:遍历时,将元素对应的数取负数,如果对应的数据为负数,说明重复

代码如下:

public class Solution
{public List<Integer> findDisappearedNumbers(int[] nums) {List<Integer> ans = new ArrayList<>();for (int i = 0; i < nums.length; i++) {int num = Math.abs(nums[i]);num--;if (nums[num] < 0) ans.add(num + 1);nums[num] = -nums[num];}return ans;}
}

LeetCode Find All Duplicates in an Array相关推荐

  1. LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] c++

    LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...

  2. Leetcode OJ: Remove Duplicates from Sorted Array I/II

    删除排序数组重复元素,先来个简单的. Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates i ...

  3. LeetCode 80. Remove Duplicates from Sorted Array II

    80. Remove Duplicates from Sorted Array II My Submissions QuestionEditorial Solution Total Accepted: ...

  4. 【leetcode】Remove Duplicates from Sorted Array

    题目:Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  5. LeetCode之Remove Duplicates from Sorted Array II

    1.题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ...

  6. LeetCode之Remove Duplicates from Sorted Array

    1.题目 Given a sorted array, remove the duplicates in place such that each element appear only once an ...

  7. LeetCode 26. Remove Duplicates from Sorted Array

    题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  8. leetcode:2680 Remove Duplicates from Sorted Array 删除数组中的重复元素

    leetcode:26 对数组元素进行去重,使得原数组重复元素最多保留1个 限制: 我们不可以额外分配数组,必须保持空间复杂度为O(1) 这个并不难实现: class Solution(object) ...

  9. leetCode #26 Remove Duplicates from Sorted Array

    删除相同数字 1 class Solution { 2 public: 3 int removeDuplicates(vector<int>& nums) { 4 int coun ...

最新文章

  1. TCP/IP中 3688端口是什么?
  2. 从键盘输入10个互不相同的整数,找出其中最小的元素将其与数组中的第一个元素进行交换。
  3. Vivado下生成及烧写MCS文件
  4. 三个数差的平方公式推导过程_勾股数公式的简单推导
  5. php pear mail 发送邮件,PHP用pear自带的mail类库发邮件
  6. 烂泥:学习ssh之ssh密钥随身携带
  7. JavaScript Oriented[探究面向对象的JavaScript高级语言特性]
  8. tts语音合成小玩具
  9. GitHub网站项目下载速度过慢、下载失败问题成功解决
  10. 华为 静态路由与FTP备份
  11. 谷歌浏览器批量图片下载插件-合成pdf
  12. bpsk调制及解调实验_调制的理解
  13. shell 脚本获取时间戳
  14. H.264 学习建议
  15. app安全测试:OWASP ZAP 2.8 使用指南(四):ZAP扫描移动应用安全
  16. 逻辑谬误_新网络谬误
  17. WPS如何并排放置两张图片_动图演示如何制作XRD叠图与PDF卡线图
  18. 用数学规划的方式求解优化问题
  19. 简洁安装HIT-SCIR(哈工大) pyltp
  20. 【Shading】Shadow Mapping 阴影映射

热门文章

  1. Sql2000命名中的’_’好象会引发问题
  2. python基础一入门必备知识-python基础教程#菜鸟也能看懂的超简单入门必备知识...
  3. 自学编程是从python语言还是c语言开始-初中生想学编程,请问先学C语言好还是先学Python?...
  4. python怎么自学、可以达到什么程度-Python学到什么程度才算精通?天津Python培训...
  5. python课程推荐-课程推荐:四天人工智能 python入门体验课
  6. python编程在哪里写程序-教你如何编写、保存与运行Python程序的方法
  7. python画折线图详解-python如何画折线图
  8. 在哪里能收到python实例代码-python仿evething的文件搜索器实例代码
  9. python学费多少-培训python学费多少?
  10. python对excel进行筛选-PythonEXCEL读取-保存-矩阵合并-条件筛选