首页 > 其他 > 详细

【leetcode 简单】第三十三题 只出现一次的数字

时间:2018-08-16 10:21:30      阅读:161      评论:0      收藏:0      [点我收藏+]

给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。

说明:

你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?

示例 1:

输入: [2,2,1]
输出: 1

示例 2:

输入: [4,1,2,1,2]
输出: 4

def make():
    fil = {}
    def filter_nums(nums):
        for i in nums:
            if i not in fil:
                fil[i] =0
            else:
                fil[i] +=1
        return [i[0] for i in fil.items() if i[1] == 0][0]
    return filter_nums

class Solution:
    def singleNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        a=make()
        return a(nums)

 

【leetcode 简单】第三十三题 只出现一次的数字

原文:https://www.cnblogs.com/flashBoxer/p/9484945.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!