2284.cpp (610B)
1 class Solution { 2 public: 3 string largestWordCount(const vector<string> &messages, const vector<string> &senders) const { 4 unordered_map<string, int> um; 5 const int n = size(messages); 6 string res; 7 int maxi = 0; 8 for (int i = 0; i < n; i++) { 9 int cnt = 0; 10 for (const char c : messages[i]) 11 cnt += c == ' '; 12 cnt = um[senders[i]] += cnt + 1; 13 if (cnt != maxi ? cnt >= maxi : senders[i] > res) { 14 res = senders[i]; 15 maxi = cnt; 16 } 17 } 18 return res; 19 } 20 };