public class Solution { public bool ContainsDuplicate(int[] nums) { var list = nums.Distinct(); if (list.Count() == nums.Length) { return false; } else { return true; } } }
https://leetcode.com/problems/contains-duplicate/#/description
python的实现:
1 class Solution: 2 def containsDuplicate(self, nums: 'List[int]') -> bool: 3 dic = {} 4 for n in nums: 5 if n not in dic: 6 dic[n] = 1 7 else: 8 return True 9 return False