Java Solution - HashMap


  • 0
    M

    public class Solution {
    public boolean containsDuplicate(int[] nums) {
    // Hash Table
    HashSet<Integer> set = new HashSet<Integer>();

        // Loop through nums
        for(int n : nums){
            if(set.contains(n)) return true;
            set.add(n);
        }
        
        return false;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.