What's wrong with my code using HashMap? Time Limit Exceeded

  • 0
    public class Solution {
        public boolean containsDuplicate(int[] nums) {
             int n = nums.length;
             HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
             for(int i = 0; i < n; i++){
                     return true;
                     hashMap.put(nums[i], i);
             return false;

  • 0

    Why you use HashMap, HashSet should be enough.

Log in to reply

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