Skip to content

Commit 4c413a5

Browse files
add 2284
1 parent faca7d0 commit 4c413a5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------|-------------
11-
| 2283 |[Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2283.java) || Easy ||
11+
| 2284 |[Sender With Largest Word Count](https://leetcode.com/problems/sender-with-largest-word-count/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2284.java) || Medium ||
12+
| 2283 |[Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2283.java) || Easy ||
1213
| 2279 |[Maximum Bags With Full Capacity of Rocks](https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2279.java) || Medium ||
1314
| 2278 |[Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2278.java) || Easy ||
1415
| 2270 |[Number of Ways to Split Array](https://leetcode.com/problems/number-of-ways-to-split-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2270.java) || Medium ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _2284 {
7+
public static class Solution1 {
8+
public String largestWordCount(String[] messages, String[] senders) {
9+
Map<String, Integer> map = new HashMap<>();
10+
for (int i = 0; i < messages.length; i++) {
11+
String sender = senders[i];
12+
int count = messages[i].split(" ").length;
13+
Integer existing = map.getOrDefault(sender, 0);
14+
map.put(sender, existing + count);
15+
}
16+
int max = 0;
17+
String result = "";
18+
for (String sender : map.keySet()) {
19+
if (map.get(sender) > max) {
20+
max = map.get(sender);
21+
result = sender;
22+
} else if (map.get(sender) == max) {
23+
if (result.compareTo(sender) < 0) {
24+
result = sender;
25+
}
26+
}
27+
}
28+
return result;
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)