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

 

posted on 2017-04-19 11:23  Sempron2800+  阅读(153)  评论(0编辑  收藏  举报