217 Contains Duplicate

public class Solution {
    public boolean containsDuplicate(int[] nums) {
       HashSet<Integer> hs = new HashSet<Integer>();
       
       for (int i : nums) {
           if (hs.contains(i)) {
               return true;
           } else {
               hs.add(i);
           }
       }
       return false;
    }
}

 

posted on 2015-05-30 08:16  kikiUr  阅读(112)  评论(0编辑  收藏  举报