Skip to content

Commit 637c0ec

Browse files
authored
Create Number of Unequal Triplets in Array.java
1 parent 5126b74 commit 637c0ec

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int unequalTriplets(int[] nums) {
3+
Map<Integer, Integer> map = new HashMap<>();
4+
for (int num : nums) {
5+
map.put(num, map.getOrDefault(num, 0) + 1);
6+
}
7+
int result = 0;
8+
int left = 0;
9+
int right = nums.length;
10+
for (Integer key : map.keySet()) {
11+
right -= map.get(key);
12+
result += left * map.get(key) * right;
13+
left += map.get(key);
14+
}
15+
return result;
16+
}
17+
}

0 commit comments

Comments
 (0)