-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3471.java
31 lines (29 loc) · 929 Bytes
/
_3471.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
package com.fishercoder.solutions.fourththousand;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeMap;
public class _3471 {
public static class Solution1 {
public int largestInteger(int[] nums, int k) {
TreeMap<Integer, Integer> map = new TreeMap<>();
for (int num : nums) {
map.put(num, 0);
}
for (int i = 0; i <= nums.length - k; i++) {
Set<Integer> set = new HashSet<>();
for (int j = i; j < i + k; j++) {
if (set.add(nums[j])) {
map.put(nums[j], map.getOrDefault(nums[j], 0) + 1);
}
}
}
int ans = -1;
for (int key : map.keySet()) {
if (map.get(key) == 1) {
ans = key;
}
}
return ans;
}
}
}