Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite24c5a6

Browse files
authored
Added Finding the Users Active Minutes.java
1 parentfd23399 commite24c5a6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
classSolution {
2+
publicint[]findingUsersActiveMinutes(int[][]logs,intk) {
3+
Map<Integer,Set<Integer>>map =newHashMap<>();
4+
List<Set<Integer>>setList =newArrayList<>();
5+
for (inti =0;i <k;i++) {
6+
setList.add(newHashSet<>());
7+
}
8+
for (int[]log :logs) {
9+
map.computeIfAbsent(log[0],j ->newHashSet<>()).add(log[1]);
10+
intcurrActiveTime =map.get(log[0]).size();
11+
if (currActiveTime <=k) {
12+
setList.get(currActiveTime -1).add(log[0]);
13+
if (currActiveTime !=1) {
14+
setList.get(currActiveTime -2).remove(log[0]);
15+
}
16+
}
17+
}
18+
int[]ans =newint[k];
19+
for (inti =0;i <k;i++) {
20+
ans[i] =setList.get(i).size();
21+
}
22+
returnans;
23+
}
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp