美文网首页
217. Contains Duplicate

217. Contains Duplicate

作者: becauseyou_90cd | 来源:发表于2018-07-31 01:46 被阅读0次

    https://leetcode.com/problems/contains-duplicate/description/
    解题思路:
    用hashset来解决

    class Solution {
    public boolean containsDuplicate(int[] nums) {

        if(nums == null) return false;
        Set<Integer> set = new HashSet<Integer>();
        for(int i = 0; i < nums.length; i++){
            if(set.contains(nums[i]))
                return true;
            set.add(nums[i]);
        }
        return false;
    }
    

    }

    相关文章

      网友评论

          本文标题:217. Contains Duplicate

          本文链接:https://www.haomeiwen.com/subject/gkxcvftx.html