###### 217. 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.

My code:

class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
n = len(nums)
if len(nums)<2:
return False
nums.sort()
for i in range(1,n):
if nums[i]== nums[i-1]:
return True
return False

Ｉｆ the dictionary is used to find the duplicates, there would be a lot of searching about the keys. So the list should be sorted first to save time.

#### LeetCode 217. Contains Duplicate（C++版）

2017-03-31 11:16:32

#### leetcode 217 Contains Duplicate 数组中是否有重复的数字

2015-08-09 21:48:10

#### LeetCode 217:Contains Duplicate

2015-05-31 18:37:10

#### leetcode 217: Contains Duplicate

2015-06-05 08:27:02

#### 【LeetCode-面试算法经典-Java实现】【217-Contains Duplicate（包含重复元素）】

2015-08-28 07:00:49

#### leetcode_c++：Contains Duplicate(217)

2016-06-18 12:40:29

#### leetcode【217+219 Contains Duplicate I+II】【python】

2016-09-08 10:33:49

#### 217. Contains Duplicate [easy] (Python)

2016-05-14 19:39:50

#### 219. Contains Duplicate II [easy] (Python)

2016-06-14 19:59:14

#### leetcode_c++：Contains Duplicate II(219)

2016-06-18 13:33:40

## 不良信息举报

217. Contains Duplicate *