当前位置:网站首页>1748. Sum of unique elements
1748. Sum of unique elements
2022-07-26 10:58:00 【Lovey_ Beihe】
Give you an array of integers nums . The only elements in an array are those that only appear Elements that happen to happen once . Please return nums Sum of unique elements in .
public static int SumOfUnique(int[] nums)
{
Dictionary<int, int> dict = new Dictionary<int, int>();
foreach (var item in nums)
{
if (dict.ContainsKey(item))// Is there in the dictionary item This key
{
dict[item]++;// If so, add one to the value corresponding to this key
}
else
{
dict.Add(item, 1);// The value corresponding to adding this key is 1
}
}
int sum = 0;
foreach (var item in dict)
{
if (item.Value == 1)// The median value of this set of key values that you cycle to is equal to 1 Words
{
sum += item.Key;// Add keys together
}
}
return sum;
}
边栏推荐
- Kali view IP address
- ThreadPoolExecutor是怎样执行任务的
- RT thread learning notes (VIII) -- start the elmfat file system based on SPI flash (Part 2)
- 1837.K进制表示下的各位数字总和
- Bash shell learning notes (6)
- 35. Search the insertion position
- How to assemble a registry?
- RT thread learning notes (I) -- configure RT thread development environment
- @NotBlank、@NotNull 、@NotEmpty 区别和使用
- Classified by the number of 1 in binary number
猜你喜欢
随机推荐
Sword finger offer (49): convert a string to an integer
WinPcap packet capturing function pcap_ Loop (), stop the problem
pytest pytest. Ini configuration case grouping case skipping
@Notblank, @notnull, @notempty differences and uses
BigDecimal's addition, subtraction, multiplication and division, size comparison, rounding up and down, and BigDecimal's set accumulation, judge whether BigDecimal has decimal
mysql学习笔记
104.二叉树的最大深度
Sql Server 数据库之数据类型
Bash shell学习笔记(二)
菜鸟看源码之HashTable
c结构体中定义的成员指针赋值与结构体指针作为成员函数参数的使用
2021-08-14 Sanzi chess
面试过程中,面试官是如何考察Rust工程师的水平?
Fragment 懒加载
Wechat official account development obtains openid times error 40029 invalid code solution
解决org.apache.commons.codec.binary.Base64爆红问题
Interview knowledge points
344.反转字符串
Esxi6.5 patch update
Bash shell learning notes (II)









