【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 ...
随机推荐
- linux stat 命令 显示文件和文件系统状态(查看文件属性) 查看文件inode
stat 显示文件和文件系统状态(查看文件属性) 查看文件inode详细信息 [root@MongoDB ~]# stat /etc/hosts File: ‘/etc/hosts’ Size: B ...
- mac搭建apace和php开发环境
启动Apache 1 先介绍几个命令 // 启动Apache服务 sudo apachectl start // 重启Apache服务 sudo apachectl restart // 停止Ap ...
- 第八周总结and实验
1.实验目的 理解异常的基本概念:掌握异常处理方法及熟悉常见异常的捕获方法. 2.实验要求 练习捕获异常.声明异常.抛出异常的方法.熟悉try和catch子句的使用.掌握自定义异常类的方法. 3.实验 ...
- 【转帖】大话Spring Cloud
springcloud(一):大话Spring Cloud 2017/05/01 http://www.ityouknow.com/springcloud/2017/05/01/simple-sp ...
- Linux下路由配置梳理(转)
转自:https://www.cnblogs.com/kevingrace/p/6490627.html 在日常运维作业中,经常会碰到路由表的操作.下面就linux运维中的路由操作做一梳理:----- ...
- set的常见用法
set的使用 set是什么 set是一个内部有序且不含重复元素的容器 用处 *使得元素自动有序 *去除重复元素 set的引入 # include <set> using namespace ...
- python——元组方法及字符串方法
元组方法 Tup.count():计算元组中指定元素出现的次数 Tup.count('c') Tup.index():在元组中从左到右查找指定元素,找到第一个就返回该元素的索引值 Tup.index( ...
- javaweb:Response/Request的概述 (转发、重定向、get/post)转
请求响应流程图 1]response 1 response概述 response是Servlet.service方法的一个参数,类型为javax.servlet.http.HttpServletR ...
- 11、权重残差图、RLE和NUSE
affyPLM包可以对芯片原始数据进行拟合回归,最后得到芯片权重(Weights)残差(Residuals)图.相对对数表达(RLE,Relative log expression)箱线图.相对标准差 ...
- JavaEE--EL表达式
EL(Expression Language)是为了使JSP写起来更加简单.表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方法,使得用户对 ...