-
Notifications
You must be signed in to change notification settings - Fork 3
/
2284.cpp
30 lines (30 loc) · 865 Bytes
/
2284.cpp
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
class Solution {
public:
int countWord(string& message) {
stringstream ss(message);
string token;
int count = 0;
while (getline(ss, token, ' ')) {
count++;
}
return count;
}
string largestWordCount(vector<string>& messages, vector<string>& senders) {
unordered_map<string, int> mp;
for (int i = 0; i < messages.size(); ++i) {
mp[senders[i]] += countWord(messages[i]);
}
int maxVal = INT_MIN;
string ans = "";
for (auto element : mp) {
if (element.second > maxVal) {
ans = element.first;
maxVal = element.second;
}
else if (element.second == maxVal) {
if (element.first > ans) ans = element.first;
}
}
return ans;
}
};