Find Lucky Integer in an Array LeetCode solution in Java

1
class Solution {
2
public int findLucky(int[] arr) {
3
HashMap<Integer, Integer> map = new HashMap<>();
4
for (int i : arr) {
5
map.put(i, map.getOrDefault(i, 0) + 1);
6
}
7
System.out.print(map);
8
int max = 0;
9
for (Map.Entry<Integer, Integer> e : map.entrySet()) {
10
int temp = 0;
11
if (e.getKey() == (int) e.getValue()) {
12
temp = (int) e.getKey();
13
}
14
if (max < temp) {
15
max = temp;
16
}
17
}
18
if (max != 0) return max;
19
return -1;
20
}
21
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0