We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f50c612 commit 813c98dCopy full SHA for 813c98d
scripts/algorithms/S/Sender With Largest Word Count/Sender With Largest Word Count.cpp
@@ -1,26 +1,27 @@
1
+// Runtime: 428 ms (Top 34.44%) | Memory: 77.6 MB (Top 40.48%)
2
class Solution {
3
public:
4
string largestWordCount(vector<string>& messages, vector<string>& senders) {
-
5
+
6
int n(size(messages));
7
map<string, int> m;
8
for (auto i=0; i<n; i++) {
9
10
stringstream ss(messages[i]);
11
string word;
12
int count(0);
- while (ss >> word) count++;
13
+ while (ss >> word) count++;
14
m[senders[i]] += count;
15
}
16
17
18
string res;
19
for (auto& p : m) {
20
if (p.second >= count) {
21
count = p.second;
- if (!res.empty() or res < p.first) res = p.first;
22
+ if (!res.empty() or res < p.first) res = p.first;
23
24
25
return res;
26
-};
27
+};
0 commit comments