1366.cpp (736B)
1 class Solution { 2 public: 3 string rankTeams(const vector<string> &votes) const { 4 static int count[27][27]; 5 memset(count, 0x00, sizeof(count)); 6 7 const int n = votes.size(), m = votes[0].size(); 8 for (const auto &vote : votes) { 9 for (int i = 0; i < m; i++) { 10 count[vote[i] & 0x1F][i]++; 11 } 12 } 13 14 string s = votes[0]; 15 sort(s.begin(), s.end(), [&](char a, char b) { 16 const int i = a & 0x1F, j = b & 0x1F; 17 for (int k = 0; k < m; k++) { 18 if (count[i][k] == count[j][k]) continue; 19 return count[i][k] > count[j][k]; 20 } 21 return a < b; 22 }); 23 return s; 24 } 25 };