217 Contains Duplicate (Array)

 1 class Solution {
 2     public boolean containsDuplicate(int[] nums) {
 3         HashMap<Integer, Integer> m = new HashMap<Integer, Integer>();
 4         for(int i = 0; i < nums.length; i++) {
 5             if (m.containsKey(nums[i])) {
 6                 return true;
 7             }else {
 8                 m.put(nums[i], 1);
 9             }
10         }
11         return false;
12     }
13 }

猜你喜欢

转载自www.cnblogs.com/goPanama/p/9375119.html