448. [LeetCode]Find All Numbers Disappeared in an Array
2016-12-29 12:01
465 查看
原文地址
这道题有两个注意点:
1. 可以使用正负号,在不改变数列中,数的大小的情况下,对数列中的数,进行标记
2. 注意返回值的形式
class Solution(object): def findDisappearedNumbers(self, nums): """ :type nums: List[int] :rtype: List[int] """ # For each number i in nums, # we mark the number that i points as negative. # Then we filter the list, get all the indexes # who points to a positive number for i in range(len(nums)): index = abs(nums[i]) - 1 nums[index] = - abs(nums[index]) return [i + 1 for i in range(len(nums)) if nums[i] > 0]
这道题有两个注意点:
1. 可以使用正负号,在不改变数列中,数的大小的情况下,对数列中的数,进行标记
2. 注意返回值的形式
相关文章推荐
- LeetCode [448. Find All Numbers Disappeared in an Array] 难度[easy]
- [LeetCode]Find All Numbers Disappeared in an Array
- [Leetcode,python] Find All Numbers Disappeared in an Array 寻找数组中消失的数字
- leetcode ---448---FindAllNumbersDisappearedinanArray
- [Leetcode,python] Find All Numbers Disappeared in an Array 寻找数组中消失的数字
- 【LeetCode-448】 Find All Numbers Disappeared in an Array(C++)
- [Leetcode,python] Find All Numbers Disappeared in an Array 寻找数组中消失的数字
- [Leetcode,python] Find All Numbers Disappeared in an Array 寻找数组中消失的数字
- [LeetCode]Find All Numbers Disappeared in an Array
- [Leetcode,python] Find All Numbers Disappeared in an Array 寻找数组中消失的数字
- [Leetcode] Find All Numbers Disappeared in an Array
- [Leetcode,python] Find All Numbers Disappeared in an Array 寻找数组中消失的数字
- [LeetCode]Find All Numbers Disappeared in an Array(Java)
- LeetCode No.448 Find All Numbers Disappeared in an Array
- 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,python] Find All Numbers Disappeared in an Array 寻找数组中消失的数字
- leetcode: Find All Numbers Disappeared in an Array
- Leetcode: Find All Numbers Disappeared in an Array