Solution using HashSet - Run time 5ms


  • 0
    A

    """
    public int findDuplicate(int[] nums) {
    HashSet<Integer> set = new HashSet<Integer>();
    for (int i : nums){
    if(!set.add(i)){
    return i;
    }
    }
    return 0;
    }

    """


Log in to reply
 

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