【leetcode】1207. Unique Number of Occurrences
题目如下:
Given an array of integers
arr, write a function that returnstrueif 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: falseExample 3:
Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
Output: trueConstraints:
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的更多相关文章
- 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)
[LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- 【LeetCode】137. Single Number II 解题报告(Python)
[LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...
- 【LeetCode】95. Unique Binary Search Trees II 解题报告(Python)
[LeetCode]95. Unique Binary Search Trees II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzh ...
- 【LeetCode】306. Additive Number 解题报告(Python)
[LeetCode]306. Additive Number 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...
- 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)
[LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...
- 【LeetCode】65. Valid Number
Difficulty: Hard More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...
- 【LeetCode】467. Unique Substrings in Wraparound String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/unique-s ...
- 【Leetcode】179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- 【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
随机推荐
- 2031 HDOJ 进制转换
Problem Description 输入一个十进制数N,将它转换成R进制数输出. Input 输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=1 ...
- "fatal error LNK1169: 找到一个或多个多重定义的符号" 解决方案
本人在测试刚刚安装的vs2017时运行出了问题, 错误信息为 "fatal error LNK1169: 找到一个或多个多重定义的符号", 代码如下: //Myfile.h #in ...
- USACO4.3 Buy Low, Buy Lower【简单dp·高精度】
如果没有方案数的话,这道题水的不得了,裸的最长下降子序列. 但是它有方案数,所以... 一个是方案数的求法: 设$f[i]$是以$a[i]$结尾的最长下降子序列的长度,可以$n^2$$dp$出答案 如 ...
- IDEA github 上传项目, 拉取, 删除
1.IDEA登录github账号 settings -> Version Controller -> GitHub 用户名密码登录 或token登录都可以 2.VCS -> impo ...
- ll按时间排序和查看目录下文件数
查询文件并以降序排列:ll -t 查询文件并以升序排列:ll -t | tac 查询目录下文件数:ll|wc -l
- 第七周课程总结&实验报告
课程总结 主要学习了抽象类与接口的应用 1.抽象类的成员可以具有访问级别 接口的成员全部public级别 2.抽象类可以包含字段 接口不可以 3.抽象类可以继承接口 接口不能继承抽象类 4.抽象类的成 ...
- 小记------mongodb数据库如何进行模糊查询
// 模糊匹配createTime 是以 2019-07-23 开头 db.getCollection('driver_online_record').find({"createTime ...
- 关于setter 和 getter方法的一些总结(初级)
1.最基础的set 和 get 准备工作 Person.h @interface Person : NSObject { NSString *_hobby; // ObjC建议成员变量带"_ ...
- lamp项目上线流程简述 (ubuntu16.04 )
1 新建一个sudo用户,而不是直接用root操作 ① 新建用户可参考 https://www.cnblogs.com/bushuwei/p/10880182.html ② 赋予sudo权限: ...
- springboot导包spring-boot-starter-parent出现错误
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...