LeetCode 448 Find All Numbers Disappeared in an Array
来源:互联网 发布:js实现下拉菜单 编辑:程序博客网 时间:2024/05/29 09:07
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements of [1, n] inclusive that do not appear in this array.
Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.
Example:
Input:[4,3,2,7,8,2,3,1]Output:[5,6]对数组遍历,如果nums[nums[i]]大于0 就把他乘以-1,本质是做标记哪些数字出现过,最后把值为正的索引输出
class Solution(object): def findDisappearedNumbers(self, nums): """ :type nums: List[int] :rtype: List[int] """ for i in range(0, len(nums)): if nums[abs(nums[i])-1] > 0: nums[abs(nums[i])-1] *= -1 return [x+1 for x in range(0,len(nums)) if nums[x] > 0]
阅读全文
0 0
- leetcode 448Find All Numbers Disappeared in an Array (array)
- LeetCode No.448 Find All Numbers Disappeared in an Array
- leetcode-448 Find All Numbers Disappeared in an Array
- 【LeetCode-448】 Find All Numbers Disappeared in an Array(C++)
- leetcode 448 Find All Numbers Disappeared in an Array C++
- Leetcode 448 Find All Numbers Disappeared in an Array
- leetcode-448- Find All Numbers Disappeared in an Array
- [LeetCode]448 Find All Numbers Disappeared in an Array
- leetcode 448 Find All Numbers Disappeared in an Array
- LeetCode 448 --- Find All Numbers Disappeared in an Array
- Leetcode #448 Find All Numbers Disappeared in an Array
- LeetCode 448 Find All Numbers Disappeared in an Array
- leetcode-448-Find All Numbers Disappeared in an Array
- [leetcode 448]Find All Numbers Disappeared in an Array
- leetcode-448 Find All Numbers Disappeared in an Array
- Leetcode 448 Find All Numbers Disappeared in an Array
- Leetcode 448 Find All Numbers Disappeared in an Array
- LeetCode 448 Find All Numbers Disappeared in an Array
- WPF下给DataGrid自动增加序列号
- divmod数字处理函数
- NotePad++编辑Linux中的文件
- 记转战AI之开篇
- phpstrom快捷键
- LeetCode 448 Find All Numbers Disappeared in an Array
- 在windows7下给vs2015配置dirent.h头文件
- 15.dubbo延迟连接、粘滞连接、令牌验证
- 《MySQL开发技巧》笔记
- Python全栈之路:字典dict常用方法
- Windows下JDK的安装配置
- 二叉树的前序遍历、中序遍历和后序遍历及其算法
- win7系统python安装
- java.io.IOException: Cannot run program "/opt/java/sdk/build-tools/23.0.1/aapt": error=2, No such fi