0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Leetcode 1207. Unique Number of Occurrences

Posted at

1207. Unique Number of Occurrences

難易度

EASY

アプローチ

HashMap, HashSet

class Solution {
    public boolean uniqueOccurrences(int[] arr) {
        
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        HashSet<Integer> set = new HashSet<>();
        for(int i : arr){
            hashMap.put(i, hashMap.getOrDefault(i,0) + 1);
        }

        for (Map.Entry<Integer,Integer> a: hashMap.entrySet()) {
            if(set.contains(a.getValue())){
                return false;
            }
            set.add(a.getValue());
        }
        
        return true;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?