forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1133.java
35 lines (32 loc) · 949 Bytes
/
_1133.java
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
28
29
30
31
32
33
34
35
package com.fishercoder.solutions;
import java.util.TreeMap;
public class _1133 {
public static class Solution1 {
public int largestUniqueNumber(int[] A) {
TreeMap<Integer, Integer> treeMap = new TreeMap<>((a, b) -> b - a);
for (int num : A) {
treeMap.put(num, treeMap.getOrDefault(num, 0) + 1);
}
for (int key : treeMap.keySet()) {
if (treeMap.get(key) == 1) {
return key;
}
}
return -1;
}
}
public static class Solution2 {
public int largestUniqueNumber(int[] A) {
int[] count = new int[1001];
for (int num : A) {
count[num]++;
}
for (int i = 1000; i >= 0; i--) {
if (count[i] == 1) {
return i;
}
}
return -1;
}
}
}