-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
27 lines (26 loc) · 827 Bytes
/
Solution.cs
File metadata and controls
27 lines (26 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace LeetCode.Problem1133{
//1133. Largest Unique Number
//https://leetcode.com/problems/largest-unique-number/
/*
Given an integer array nums, return the largest integer that only occurs once. If no integer occurs once, return -1.
*/
public class Solution {
public int LargestUniqueNumber(int[] nums) {
Dictionary<int,int> dic = new Dictionary<int,int>();
int ans = 0;
for (int i = 0; i < nums.Length; i++)
{
var value = nums[i];
if (dic.ContainsKey(value))
dic[value]++;
else
dic.Add(value,1);
}
if (dic.ContainsValue(1))
ans = dic.Where(p => p.Value == 1).Select(p => p.Key).OrderBy(p => p).LastOrDefault();
else
ans = -1;
return ans;
}
}
}