forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_2284.java
31 lines (29 loc) · 1.02 KB
/
_2284.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _2284 {
public static class Solution1 {
public String largestWordCount(String[] messages, String[] senders) {
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i < messages.length; i++) {
String sender = senders[i];
int count = messages[i].split(" ").length;
Integer existing = map.getOrDefault(sender, 0);
map.put(sender, existing + count);
}
int max = 0;
String result = "";
for (String sender : map.keySet()) {
if (map.get(sender) > max) {
max = map.get(sender);
result = sender;
} else if (map.get(sender) == max) {
if (result.compareTo(sender) < 0) {
result = sender;
}
}
}
return result;
}
}
}