国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【LeetCode】448. Find All Numbers Disappeared in an Array【E】【77】

2019-11-08 02:50:17
字體:
來源:轉載
供稿:網友

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]

Subscribe to see which companies asked this question.方法一想法很簡單,把list轉成set 直接就去重了,然后從1到n,挨個判斷是否在set里方法二For each number i in nums,we mark the number that i points as negative.Then we filter the list, get all the indexeswho points to a positive number.Since those indexes are not visited.
class Solution(object):    def findDisappearedNumbers(self, nums):        for i in xrange(len(nums)):            ind = abs(nums[i]) - 1            nums[ind] = - abs(nums[ind])        res = []        for i in xrange(len(nums)):            if nums[i] > 0:                res += i+1,        return res        '''        l = len(nums)        nums = set(nums)        res = []        for i in range(1,l+1):            if i not in nums:                res += i,        return res        '''        """        :type nums: List[int]        :rtype: List[int]        """
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绍兴县| 连平县| 阿拉善右旗| 泽库县| 铜山县| 乐都县| 襄垣县| 都昌县| 黄平县| 孟村| 富民县| 遂溪县| 浏阳市| 阳新县| 陆丰市| 七台河市| 灌阳县| 安泽县| 东安县| 敖汉旗| 桦川县| 荆州市| 漳平市| 东乌| 永昌县| 仪征市| 云和县| 巨鹿县| 上蔡县| 松桃| 扎兰屯市| 林州市| 隆安县| 灌阳县| 和平县| 江永县| 武义县| 额济纳旗| 云和县| 措美县| 晋江市|