forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2150.java
27 lines (25 loc) · 828 Bytes
/
_2150.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
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
public class _2150 {
public static class Solution1 {
public List<Integer> findLonely(int[] nums) {
TreeMap<Integer, Integer> treeMap = new TreeMap<>();
for (int num : nums) {
treeMap.put(num, treeMap.getOrDefault(num, 0) + 1);
}
List<Integer> ans = new ArrayList<>();
for (int key : treeMap.keySet()) {
if (treeMap.get(key) > 1) {
continue;
} else {
if (!treeMap.containsKey(key - 1) && !treeMap.containsKey(key + 1)) {
ans.add(key);
}
}
}
return ans;
}
}
}