leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1366.cpp (736B)


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