18ms solution used by Map


  • 1
    M

    public class Solution {
    public boolean containsDuplicate(int[] nums) {

        if(null == nums||nums.length == 0){
            
            return false;
        }
        
        Map<Integer,Integer> map = new HashMap<Integer,Integer>(); 
        
        for(int i = 0;i<nums.length;i++){
            
            if(null == map.get(nums[i])){
                
                map.put(nums[i],1);
                
            }else{
                
                map.put(nums[i],map.get(nums[i]) + 1);
                
                if(map.get(nums[i])>=2){
                    
                    return true;
                }
                
                
                
            }
            
            
        }
        return false;
        
    }
    

    }


Log in to reply
 

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