Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 176e378

Browse files
add 2150
1 parent 43cc87b commit 176e378

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2150|[Find All Lonely Numbers in the Array](https://leetcode.com/problems/find-all-lonely-numbers-in-the-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2150.java) ||Medium||
1112
|2149|[Rearrange Array Elements by Sign](https://leetcode.com/problems/rearrange-array-elements-by-sign/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2149.java) ||Medium||
1213
|2148|[Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2148.java) ||Easy||
1314
|2144|[Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2144.java) ||Easy||
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.TreeMap;
6+
7+
public class _2150 {
8+
public static class Solution1 {
9+
public List<Integer> findLonely(int[] nums) {
10+
TreeMap<Integer, Integer> treeMap = new TreeMap<>();
11+
for (int num : nums) {
12+
treeMap.put(num, treeMap.getOrDefault(num, 0) + 1);
13+
}
14+
List<Integer> ans = new ArrayList<>();
15+
for (int key : treeMap.keySet()) {
16+
if (treeMap.get(key) > 1) {
17+
continue;
18+
} else {
19+
if (!treeMap.containsKey(key - 1) && !treeMap.containsKey(key + 1)) {
20+
ans.add(key);
21+
}
22+
}
23+
}
24+
return ans;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)