leetcode:442. Find All Duplicates in an Array
来源:互联网 发布:全国所有中小学数据库 编辑:程序博客网 时间:2024/06/04 19:28
即找出数组中的重复的数字,题目咋一看比较简单,但是要求不允许使用额外的空间,复杂度为o(n)
class Solution(object): def findDuplicates(self, nums): """ :type nums: List[int] :rtype: List[int] """ return [nums[i] for i in range(len(nums)) if nums[i] in nums[:i]]
随手写的,此答案复杂度超了
以下答案转换数据、下标,应多加思考
class Solution(object): def findDuplicates(self, nums): """ :type nums: List[int] :rtype: List[int] """ res = [] for x in nums: print(nums) if nums[abs(x) - 1] < 0: res.append(abs(x)) else: nums[abs(x) - 1] *= -1 print(nums) return res
0 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] 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)
- [LeetCode]442. Find All Duplicates 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
- [leetcode]442. Find All Duplicates in an Array
- Leetcode 442. Find All Duplicates in an Array
- LeetCode 442. Find All Duplicates in an Array
- 代码行数统计
- Shader山下(二十四)相机深度纹理
- YAML 语言教程
- 线段树
- 搭建Git服务器
- leetcode:442. Find All Duplicates in an Array
- android自定义路径的属性动画
- 【解惑】深入jar包:从jar包中读取资源文件
- 路由器的串口(serial)和以太口的区别
- 微信小程序开发教程(基础篇)5-index 页面解析
- shiro 配置首先访问地址
- HashMap和HashTable的选择
- Ubuntu中安装JDK
- 表单按钮倒计时 》验证码 jQuery&&JavaScript