当前位置:网站首页>1748.唯一元素的和
1748.唯一元素的和
2022-07-26 10:41:00 【Lovey_北禾】
给你一个整数数组 nums 。数组中唯一元素是那些只出现 恰好一次的元素。请你返回 nums 中唯一元素的和 。
public static int SumOfUnique(int[] nums)
{
Dictionary<int, int> dict = new Dictionary<int, int>();
foreach (var item in nums)
{
if (dict.ContainsKey(item))//字典里面有没有item这个键
{
dict[item]++;//如果有就把这个键对应的值加一
}
else
{
dict.Add(item, 1);//添加这个键对应的值是1
}
}
int sum = 0;
foreach (var item in dict)
{
if (item.Value == 1)//循环到的这一组键值中值等于1的话
{
sum += item.Key;//把键加到一起
}
}
return sum;
}
边栏推荐
- (转载)ArcGIS Engine中各种点的创建方法
- Issue 6: which mainstream programming language should college students choose
- Issue 5: the second essential skill for College Students
- [转]ArcGIS中判断两个Geometry之间的关系
- [machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)
- C language calculation date interval days
- 使用grid实现左中右布局,中间内容自适应
- 第5期:大学生入职必备技能之二
- 剑指Offer(五十三):表示数值的字符串
- Codepoint 58880 not found in font, aborting. flutter build apk时报错
猜你喜欢
![[leetcode daily question 2021/4/23]368. Maximum divisible subset](/img/0b/32ca862963c842a93f79eaac94fb98.png)
[leetcode daily question 2021/4/23]368. Maximum divisible subset

.net5wtm (asp.net core) PgSQL unpacking operation

英语基础句型结构------起源
![[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array](/img/9d/5ce5d4144a9edc3891147290e360d8.png)
[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array

Issue 8: cloud native -- how should college students learn in the workplace

【机器学习小记】【风格迁移】deeplearning.ai course4 4th week programming(tensorflow2)

抽象工厂及其改进示例
![[leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字](/img/9b/624416fa6a408bf64ca5438273176b.png)
[leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字

第8期:云原生—— 大学生职场小白该如何学
![[leetcode每日一题2021/8/31]1109. 航班预订统计【中等】差分数组](/img/9d/5ce5d4144a9edc3891147290e360d8.png)
[leetcode每日一题2021/8/31]1109. 航班预订统计【中等】差分数组
随机推荐
Flutter CachedNetworkImage圆角
[dectectron2] follow the official demo
(转载)ArcGIS Engine中各种点的创建方法
RT-Thread 学习笔记(八)---开启基于SPI Flash的elmfat文件系统(下)
构建ARM嵌入式开发环境
使用定位实现左中右布局,中间内容自适应
putty的使用教程
Issue 5: the second essential skill for College Students
控制随机抽中几率 [ C# | Random ]
[paper after dinner] deep mining external perfect data for chestx ray disease screening
oracle 启动不了 tnslistener服务启动不了
点击el-dropdown-item/@click.native
Redis special data type usage scenarios
[leetcode daily question 2021/4/23]368. Maximum divisible subset
Codepoint 58880 not found in font, aborting. flutter build apk时报错
10 let operator= return a reference to *this
2021-08-12函数递归_和鹏哥学习C语言
使用flex实现左中右布局,中间自适应
[leetcode daily question 2021/5/8]1723. The shortest time to complete all work
Parallelism, concurrency and several directions for high concurrency optimization