Solution:
# T:O(n) S:O(n) class Solution: # @param {integer[]} nums # @param {integer} k # @return {boolean} def containsNearbyDuplicate(self, nums, k): if k >= len(nums) - 1: return len(nums) > len(set(nums)) for i in xrange(k, len(nums)): tmp = nums[i-k:i+1] if len(tmp) > len(set(tmp)): return True else: return FalseRun Time: 60 ms
No comments:
Post a Comment