-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1366.cpp
More file actions
25 lines (23 loc) · 736 Bytes
/
Copy path1366.cpp
File metadata and controls
25 lines (23 loc) · 736 Bytes
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
class Solution {
public:
string rankTeams(const vector<string> &votes) const {
static int count[27][27];
memset(count, 0x00, sizeof(count));
const int n = votes.size(), m = votes[0].size();
for (const auto &vote : votes) {
for (int i = 0; i < m; i++) {
count[vote[i] & 0x1F][i]++;
}
}
string s = votes[0];
sort(s.begin(), s.end(), [&](char a, char b) {
const int i = a & 0x1F, j = b & 0x1F;
for (int k = 0; k < m; k++) {
if (count[i][k] == count[j][k]) continue;
return count[i][k] > count[j][k];
}
return a < b;
});
return s;
}
};