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;
}
}
网友评论