forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_2148.java
More file actions
24 lines (22 loc) · 668 Bytes
/
_2148.java
File metadata and controls
24 lines (22 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.fishercoder.solutions;
import java.util.TreeMap;
public class _2148 {
public static class Solution1 {
public int countElements(int[] nums) {
TreeMap<Integer, Integer> treeMap = new TreeMap<>();
for (int num : nums) {
treeMap.put(num, treeMap.getOrDefault(num, 0) + 1);
}
int ans = 0;
int i = 0;
int len = treeMap.size();
for (int key : treeMap.keySet()) {
if (i != 0 && i != len - 1) {
ans += treeMap.get(key);
}
i++;
}
return ans;
}
}
}