赞
踩
题目链接:
力扣
https://leetcode-cn.com/problems/contains-duplicate/
【分析】直接用哈希表
- class Solution {
- public boolean containsDuplicate(int[] nums) {
-
- Set<Integer> set = new HashSet<>();
- int n = nums.length;
- for(int i = 0; i < n; i++){
- if(set.contains(nums[i])) return true;
- set.add(nums[i]);
- }
- return false;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。