Saturday, August 29, 2015

Leetcode 217. Contains Duplicate

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

We can use set in Python, which has the feature of getting rid of duplicate automatically.

Solution:
# T:O(n) S:O(n)
class Solution:
    # @param {integer[]} nums
    # @return {boolean}
    def containsDuplicate(self, nums):
        return len(nums) > len(set(nums))
Run Time: 80 ms

No comments:

Post a Comment