Simple Java solution


  • 0
    C
    public class Solution {
        public boolean containsDuplicate(int[] nums) {
            HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
            for(int i = 0; i < nums.length; i++){
                if(map.containsKey(nums[i])){
                    return true;
                }else{
                    map.put(nums[i],i);
                }
            }
            return false;
        }
    }
    

Log in to reply
 

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