LeetCode-Contains Duplicate

Posted IncredibleThings

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode-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.
public class Solution {
    public boolean containsDuplicate(int[] nums) {
        if(nums == null){
            return false;
        }
        HashSet<Integer> set=new HashSet<Integer>();
        int len =nums.length;
        for(int i=0; i<len; i++){
            if(set.contains(nums[i])){
                return true;
            }
            else{
                set.add(nums[i]);
            }
        }
        return false;
    }
}

  

以上是关于LeetCode-Contains Duplicate的主要内容,如果未能解决你的问题,请参考以下文章

leetCode-Contains Duplicate II

GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 错误

 Failed to destroy end point associated with ProtocolHandler["ajp-nio-8009"] Duplica

PHP返回error500 [重复]

Ubuntu apache vhostu别名安装程序

MySQL INSERT ON DUPLICATE KEY UPDATE