Skip to content

Commit e8a6150

Browse files
add 1817
1 parent a0e3c1c commit e8a6150

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

+1
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+
|1817|[Finding the Users Active Minutes](https://leetcode.com/problems/finding-the-users-active-minutes/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1817.java) ||Medium|HashTable|
1112
|1816|[Truncate Sentence](https://leetcode.com/problems/truncate-sentence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1816.java) ||Easy|String|
1213
|1813|[Sentence Similarity III](https://leetcode.com/problems/sentence-similarity-iii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1813.java) ||Medium|String|
1314
|1812|[Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1812.java) ||Easy|String|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.HashSet;
5+
import java.util.Map;
6+
import java.util.Set;
7+
import java.util.TreeMap;
8+
9+
public class _1817 {
10+
public static class Solution1 {
11+
public int[] findingUsersActiveMinutes(int[][] logs, int k) {
12+
Map<Integer, Set<Integer>> map = new HashMap<>();
13+
for (int[] log : logs) {
14+
int user = log[0];
15+
if (!map.containsKey(user)) {
16+
map.put(user, new HashSet<>());
17+
}
18+
Set<Integer> set = map.get(user);
19+
set.add(log[1]);
20+
}
21+
int[] result = new int[k];
22+
TreeMap<Integer, Integer> treeMap = new TreeMap<>();
23+
for (int key : map.keySet()) {
24+
int uam = map.get(key).size();
25+
treeMap.put(uam, treeMap.getOrDefault(uam, 0) + 1);
26+
}
27+
for (int key : treeMap.keySet()) {
28+
result[key - 1] = treeMap.get(key);
29+
}
30+
return result;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)