@@ -60,13 +60,81 @@ Since there is a tie for the largest word count, we return the sender with the l
60
60
### ** Python3**
61
61
62
62
``` python
63
-
63
+ class Solution :
64
+ def largestWordCount (self , messages : List[str ], senders : List[str ]) -> str :
65
+ cnt = Counter()
66
+ for m, s in zip (messages, senders):
67
+ cnt[s] += m.count(' ' ) + 1
68
+ return sorted (cnt.items(), key = lambda x : (x[1 ], x[0 ]))[- 1 ][0 ]
64
69
```
65
70
66
71
### ** Java**
67
72
68
73
``` java
74
+ class Solution {
75
+ public String largestWordCount (String [] messages , String [] senders ) {
76
+ Map<String , Integer > cnt = new HashMap<> ();
77
+ int n = senders. length;
78
+ for (int i = 0 ; i < n; ++ i) {
79
+ cnt. put(senders[i], cnt. getOrDefault(senders[i], 0 ) + messages[i]. split(" " ). length);
80
+ }
81
+ String ans = senders[0 ];
82
+ for (Map . Entry<String , Integer > e : cnt. entrySet()) {
83
+ String u = e. getKey();
84
+ int v = e. getValue();
85
+ if (v > cnt. get(ans) || (v == cnt. get(ans) && ans. compareTo(u) < 0 )) {
86
+ ans = u;
87
+ }
88
+ }
89
+ return ans;
90
+ }
91
+ }
92
+ ```
93
+
94
+ ### ** C++**
95
+
96
+ ``` cpp
97
+ class Solution {
98
+ public:
99
+ string largestWordCount(vector<string >& messages, vector<string >& senders) {
100
+ unordered_map<string, int> cnt;
101
+ int n = senders.size();
102
+ for (int i = 0; i < n; ++i)
103
+ {
104
+ int v = 0;
105
+ for (char& c : messages[ i] )
106
+ {
107
+ if (c == ' ') ++v;
108
+ }
109
+ cnt[ senders[ i]] += v + 1;
110
+ }
111
+ string ans = senders[ 0] ;
112
+ for (auto& [ u, v] : cnt)
113
+ {
114
+ if (v > cnt[ ans] || (v == cnt[ ans] && u > ans)) ans = u;
115
+ }
116
+ return ans;
117
+ }
118
+ };
119
+ ```
69
120
121
+ ### **Go**
122
+
123
+ ```go
124
+ func largestWordCount(messages []string, senders []string) string {
125
+ cnt := map[string]int{}
126
+ for i, msg := range messages {
127
+ v := strings.Count(msg, " ") + 1
128
+ cnt[senders[i]] += v
129
+ }
130
+ ans := ""
131
+ for u, v := range cnt {
132
+ if v > cnt[ans] || (v == cnt[ans] && u > ans) {
133
+ ans = u
134
+ }
135
+ }
136
+ return ans
137
+ }
70
138
```
71
139
72
140
### ** TypeScript**
0 commit comments