Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Files
Expand file tree
main
Breadcrumbs
leetcode-java-streams
/
src
/
LeetCode3945.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
聽
History
History
History
22 lines (20 loc) 路 688 Bytes
main
Breadcrumbs
leetcode-java-streams
/
src
/
LeetCode3945.java
Copy path
Top
File metadata and controls
Code
Blame
22 lines (20 loc) 路 688 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.function.Function;
import java.util.stream.Collectors;
//3945. Digit Frequency Score
public class LeetCode3945 {
public int digitFrequencyScore(int n) {
return Integer.toString(n).chars()
.map(d -> d - '0')
.sum();
}
public int digitFrequencyScore_2(int n) {
return (int) Integer.toString(n).chars()
.map(d -> d - '0')
.boxed()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet()
.stream()
.mapToLong(entry -> entry.getKey() * entry.getValue())
.sum();
}
}
You can鈥檛 perform that action at this time.