题目如下:

Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique.

Example 1:

Input: arr = [1,2,2,1,1,3]
Output: true
Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.

Example 2:

Input: arr = [1,2]
Output: false

Example 3:

Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
Output: true

Constraints:

  • 1 <= arr.length <= 1000
  • -1000 <= arr[i] <= 1000

解题思路:很简单的题目。

代码如下:

class Solution(object):
def uniqueOccurrences(self, arr):
"""
:type arr: List[int]
:rtype: bool
"""
dic = {}
for i in arr:
dic[i] = dic.setdefault(i,0) + 1
dic_exist = {}
for v in dic.itervalues():
if v in dic_exist:
return False
dic_exist[v] = 1
return True

【leetcode】1207. Unique Number of Occurrences的更多相关文章

  1. 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)

    [LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  2. 【LeetCode】137. Single Number II 解题报告(Python)

    [LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...

  3. 【LeetCode】95. Unique Binary Search Trees II 解题报告(Python)

    [LeetCode]95. Unique Binary Search Trees II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzh ...

  4. 【LeetCode】306. Additive Number 解题报告(Python)

    [LeetCode]306. Additive Number 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...

  5. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  6. 【LeetCode】65. Valid Number

    Difficulty: Hard  More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...

  7. 【LeetCode】467. Unique Substrings in Wraparound String 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/unique-s ...

  8. 【Leetcode】179. Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  9. 【LeetCode】63. Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

随机推荐

  1. oracle 11g错误ora-01033:oracle initialization or shutdown in progress解决办法

    原文出自:http://blog.csdn.net/liverliu/article/details/6410287 一.首先:问题的产生原因,先前我在f:/llh/目录创建的一个bookspace表 ...

  2. codeblocks无法识别的16位程序解决方法

    被codeblocks心态搞崩了,分享一下经验给大家,具体就是无法运行编译好的程序,还有就是调试功能没法用. 查了很多资料,自己搞了一个终极解决方法:1卸载codeblocks,2打开我的电脑,全盘搜 ...

  3. C语言循环队列

    #include<stdio.h> #include<stdlib.h> #include<string.h> //循环队列 typedef struct { in ...

  4. Keytool生成证书

    一.生成证书keytool -genkey -alias 别名 -keyalg RSA -keysize 1024(密钥位数) -keypass 密码 -validity 365(默认90天) -ke ...

  5. 【6.18校内test】T1多项式输出

    日常题前废话: 首先so amazing 的一件事,因为在洛谷上立下了的flag,然后这次考试前两道题都是刚刚做过不久的题emmm(相当于白送200吗qwq,但是这阻挡不了我第三题不会的脚步qwq) ...

  6. [Codeforces 1245D] Shichikuji and Power Grid (最小生成树)

    [Codeforces 1245D] Shichikuji and Power Grid (最小生成树) 题面 有n个城市,坐标为\((x_i,y_i)\),还有两个系数\(c_i,k_i\).在每个 ...

  7. redis 列表 数据类型

    列表 rpush dname  技术部  后勤部 售后部 lpush  dname   秘书部 lset dname 2  销售部     修改 lrange dname 0 -1   打印所有列表 ...

  8. [LeetCode] 完全二叉树的节点个数

    题目链接: https://leetcode-cn.com/problems/count-complete-tree-nodes 难度:中等 通过率:57.4% 题目描述: 给出一个 完全二叉树 ,求 ...

  9. php常用header状态

    <?php //200 正常状态 header('HTTP/1.1 200 OK'); // 301 永久重定向,记得在后面要加重定向地址 Location:$url header('HTTP/ ...

  10. Tensorflow API 学习(1)-tf.slice()

    slice()函数原型为: tf.slice(input_, begin, size, name=None) 函数有4个参数: 1,input_ :图片的矩阵输入格式. 2,begin :开始截取的位 ...