# 问题描述

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.

# Python

`class Solution:    # @param {integer[]} nums    # @return {boolean}    def containsDuplicate(self, nums):        nums.sort()        l = len(nums)        for i in xrange(l-1):            if nums[i] == nums[i+1]:                return True        return False`

python语言特点做法,提用set集合

`class Solution(object):    def containsDuplicate(self, nums):        """        :type nums: List[int]        :rtype: bool        """        return False if len(nums) == len(set(nums)) else True`

# Java

`public class Solution {    public boolean containsDuplicate(int[] nums) {        Set<Integer> set = new HashSet();        for (int num : nums) {            if (!set.add(num)) return true;        }        return false;    }​}`

# Golang

`package main​import (    "fmt"    "sort")​func ContainsDuplicate(nums []int) bool {    sort.Ints(nums)    for idx := 0; idx < len(nums)-1; idx++ {        if nums[idx] == nums[idx+1] {            return true        }    }    return false}​func main() {    nums := []int{3, 1, 4, 3, 2}    nums2 := []int{3, 4, 6, 5}​    fmt.Println(ContainsDuplicate(nums[:]))    fmt.Println(ContainsDuplicate(nums2[:]))}`