记录leetcode的java提交解答

class Solutions {
	//217.存在重复元素
    public boolean containsDuplicate(int[] nums) {
    	if (nums.length == 0) {
    		return false;
    	}
    	Set<Integer> hashset = new HashSet<>(nums.length);
    	for (int i = 0; i < nums.length - 1; i++) {
    		if (hashset.contains(nums[i])) {
    			return true;
    		}
    		hashset.add(nums[i]);
    	}
    	return false;
    }
}

猜你喜欢

转载自www.cnblogs.com/hanhande/p/12805882.html