Java-LeetCode1207. 独一无二的出现次数-HashMap&HashSet

  • 算法
    • HashMap + HashSet
public boolean uniqueOccurrences(int[] arr) {
    HashMap<Integer, Integer> map = new HashMap<>();
    for (int x : arr) {
        map.put(x, map.getOrDefault(x, 0) + 1);
    }
    return map.size() == new HashSet<Integer>(map.values()).size();
}
全部评论

相关推荐

仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务