public class Solution {
public boolean containsDuplicate(int[] nums) {
if(nums.length==0) return false;
HashSet<Integer> h=new HashSet<Integer>();
for(int i:nums)
if( h.add(i)==false) return true;
return false;
}
}leetcode:Contains Duplicate
最新推荐文章于 2017-05-14 20:15:42 发布
本文介绍了一种使用Java HashSet来检测整数数组中是否存在重复元素的方法。通过遍历数组并将元素添加到HashSet中,若添加失败则表明该元素已存在,从而确定数组中有重复的元素。
775

被折叠的 条评论
为什么被折叠?



