Leetcode-5205 Unique Number of Occurrences(独一无二的出现次数)

本文介绍了一种使用C++实现的方法,该方法能够判断一个整数数组中每个元素出现的次数是否都是唯一的。通过定义哈希表并进行两层循环遍历的方式,有效地解决了这一问题。
 1 typedef long long ll;
 2 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 3 #define _rep(i,a,b) for(int i = (a);i > b;i --)
 4 #define INF 0x3f3f3f3f
 5 #define pb push_back
 6 #define maxn 10000
 7 
 8 class Solution
 9 {
10     public:
11         bool uniqueOccurrences(vector<int>& arr)
12         {
13             int Hash[2003];
14             memset(Hash,0,sizeof(Hash));
15             _for(i,0,arr.size())
16                 Hash[arr[i]+1000] ++;
17             
18             _for(i,0,2001)
19             {
20                 _for(j,i+1,2001)
21                 {
22                     if(Hash[i] && Hash[i]==Hash[j])
23                         return false;
24                 }
25             }
26             return true;
27         }
28 };

 

转载于:https://www.cnblogs.com/Asurudo/p/11607861.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值