LeetCode217存在重复元素

LeetCode217存在重复元素

未经博主同意,禁止瞎JB转载。

https://leetcode-cn.com/problems/contains-duplicate/description/

我的解法:

字典

class Solution(object):
    def containsDuplicate(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        ret = {}
        for i in nums:
            if i in ret:
                return True
            else:
                ret[i] = 1
        return False

 

posted @ 2018-10-25 21:10  嬴政有条北冥的鱼  阅读(116)  评论(0编辑  收藏  举报