leetcode之Find All Duplicates in an Array 问题
来源:互联网 发布:钢琴可以自学吗 知乎 编辑:程序博客网 时间:2024/05/29 17:25
问题描述:
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array),some elements appear twice and others appear once.
Find all the elements that appear twice in this array.
Could you do it without extra space and in O(n) runtime?
题目要求找到相同的数,每个数的大小范围是1~n。要求给出的答案中时间复杂度是O(n),空间复杂度是O(1)
示例:
Example:
Input:
[4,3,2,7,8,2,3,1]
Output:
[2,3]
题目来源:Find All Duplicates in an Array (具体地址:https://leetcode.com/problems/find-all-duplicates-in-an-array/#/description)
思路:题目给出的值的大小在1到n之间,而我们的数组索引在0~n-1,那我们就把它处理一下喽,变成0 ≤ a[i] - 1≤n - 1。接下来就是比较常见的数组索引的把戏了吧。具体参见下面代码吧。可以和Find All Numbers Disappeared in an Array 关联起来阅读,详细解答Find All Numbers Disappeared in an Array相关解答也给出来。
代码:
阅读全文
1 0
- leetcode之Find All Duplicates in an Array 问题
- [LeetCode]Find All Duplicates in an Array
- LeetCode Find All Duplicates in an Array
- Leetcode Find All Duplicates in an Array
- [Leetcode] Find All Duplicates in an Array
- leetCode-Find All Duplicates in an Array
- LeetCode之Find All Duplicates in an Array
- Leetcode 442 - Find All Duplicates in an Array (array)
- LeetCode-Find All Duplicates in an Array & Find All Numbers Disappeared in an Array
- leetcode之 Find All Numbers Disappeared in an Array 问题
- [leetcode] 442. Find All Duplicates in an Array
- LeetCode 442. Find All Duplicates in an Array
- leetcode:442. Find All Duplicates in an Array
- 442. Find All Duplicates in an Array(LeetCode)
- <leetcode>442. Find All Duplicates in an Array
- [leetcode]442. Find All Duplicates in an Array(java)
- [C语言][LeetCode][442]Find All Duplicates in an Array
- [LeetCode]442. Find All Duplicates in an Array
- Url接口测试:HttpClient模拟登录效果
- Java Socket实现简单的即时通信
- C ~ 指针的运算
- Android BroadcastReceiver实现自定义静态广播和动态广播(黏性广播)
- KMP算法(各种模板)
- leetcode之Find All Duplicates in an Array 问题
- psr 命名空间的规范
- 【Python】【并行计算】Python 多核并行计算
- POJ3734 矩阵快速幂
- 设计模式应用相关面试题目
- 【异常】Session 0x0 for server null, unexpected error, closing socket connection and attempting reconn
- 面向对象编程之常用关键字instanceof和final
- JavaScript isNaN() 函数
- 归并排序例子(2017.07.11)