Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> uniques = new HashSet<>(); for (int num : nums) { if (uniques.contains(num)) { return true; } uniques.add(num); } return false; } }
إرسال تعليق