Leetcode: Contains Duplicate

Contains Duplicate



Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

Github: code.dennyzhang.com

Credits To: leetcode.com

Leave me comments, if you have better ways to solve.


## Blog link: https://code.dennyzhang.com/contains-duplicate
## Complexity: Time O(n*log(n)), Space O(n)
class Solution(object):
    def containsDuplicate(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        return len(nums) != len(set(nums))
linkedin
github
slack

Share It, If You Like It.

Leave a Reply

Your email address will not be published.