import 'dart:collection';

bool uniqueOccurrences(List arr) { Map<int, int> occur = HashMap<int, int>(); for (int x in arr) { occur[x] = occur.containsKey(x) ? occur[x] + 1 : 1; } Set times = HashSet(); for (MapEntry<int, int> x in occur.entries) { times.add(x.value); } return times.length == occur.length; }

class Solution public boolean uniqueOccurrencesint arr MapInteger Integer occur = new HashMapInteger Integer; for int x arr occurputx occurgetOrDefaultx 0 + 1;

原文地址: https://www.cveoy.top/t/topic/iAyS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录