国产探花免费观看_亚洲丰满少妇自慰呻吟_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]        """
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 军事| 诏安县| 卫辉市| 尼木县| 哈密市| 延川县| 祁门县| 温宿县| 左云县| 华安县| 长宁区| 济阳县| 利辛县| 江山市| 曲周县| 贡嘎县| 微山县| 清水河县| 东至县| 沙湾县| 大渡口区| 英吉沙县| 新蔡县| 汉中市| 若羌县| 灌云县| 瑞金市| 横山县| 莱芜市| 潮安县| 郁南县| 黄骅市| 四平市| 中卫市| 永定县| 红河县| 临城县| 灌南县| 大连市| 清水河县| 宁武县|