题目如下:

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:

  1. Input: arr = [1,2,2,1,1,3]
  2. Output: true
  3. 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:

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

Example 3:

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

Constraints:

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

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

代码如下:

  1. class Solution(object):
  2. def uniqueOccurrences(self, arr):
  3. """
  4. :type arr: List[int]
  5. :rtype: bool
  6. """
  7. dic = {}
  8. for i in arr:
  9. dic[i] = dic.setdefault(i,0) + 1
  10. dic_exist = {}
  11. for v in dic.itervalues():
  12. if v in dic_exist:
  13. return False
  14. dic_exist[v] = 1
  15. 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. C#学习笔记二 (资源托管,泛型,数组和元组,运算符和类型强制转换)

     托管和非托管资源 1.托管资源是指GC管理的内存空间,非托管资源是指文件句柄,网络连接,数据库连接等. 2.方法中临时申请的变量,被存放在栈中.栈存储非对象成员的值数据.例如在方法中有B b=new ...

  2. Python学习之面向对象(一)

    第六章 面向对象 6.1 面向对象的初识 6.1.1 什么是面向对象 面向过程式编程: ​ 好处:出色的完成所有的需求 ​ 坏处:凡是更改或者增加一条需求,可能整个项目都随之改变 面向对象式编程: 类 ...

  3. 记一次nginx配置伪静态规则

    server { listen 80; server_name sss.cn; root "root/"; location / { index index.html index. ...

  4. python基础--面向对象之多态

    # 多态是指一类事物有多种行态, # 例如:动物有多种形态:人,狗,猫 # 他们有一些共同的特征:吃,喝,拉,撒 # 多态性是指在不考虑实例类型的情况下使用实例 # 对同一事物不同的类,对象有不同的响 ...

  5. 数据库SQL语句查询指定时间段内的数据

    [摘要]有的时候,我们需要查询数据库某段时间之间的数据,比如2016年5月1号到到5月3号之间用户注册数量(特殊节假日期间)等.那么用SQL语句如何实现呢? 首先,数据表中的存时间的字段比如是addt ...

  6. python 并发编程 io模型 目录

    python 并发编程 IO模型介绍 python 并发编程 socket 服务端 客户端 阻塞io行为 python 并发编程 阻塞IO模型 python 并发编程 非阻塞IO模型 python 并 ...

  7. java.time包常用类API学习记录

    Java8出来已那么多年了,java.time包之前一直没有使用过,最近正好有用到,在此做个记录. 上图列出了java.time包下的类,接下来我们详细看下其中每个类的用法. Clock:获取到当前时 ...

  8. Dubbo-zooKeeper入门讲解

    1.Dubbo-zooKeeper史上最简单入门实例 2.Dubbo官方文档

  9. Connection is read-only. Queries leading to data modification are not allowed 错误原因

    因为我再spring 中使用了AOP进行事务管理,有如下配置 <tx:advice id="txAdvice" transaction-manager="trans ...

  10. [转帖]Linux下inotify监控文件夹状态,发生变化后触发rsync同步

    Linux下inotify监控文件夹状态,发生变化后触发rsync同步 https://www.cnblogs.com/fjping0606/p/6114123.html 1.安装工具--inotif ...