1207. Unique Number of Occurrences

1207. Unique Number of Occurrences

class Solution {
    public boolean uniqueOccurrences(int[] arr) {
        HashMap h = new HashMap();
        for(int i = 0; i < arr.length; i++) {
        	h.put(arr[i], h.getOrDefault(arr[i],0)+1);
        if(h.size() == 0) return true;
        HashSet repeats = new HashSet();
        for (Integer a: h.keySet()) {
        	if(repeats.contains(h.get(a))) return false;
        	else repeats.add(h.get(a));
        return true;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s