forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1366.java
More file actions
21 lines (18 loc) · 694 Bytes
/
1366.java
File metadata and controls
21 lines (18 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public String rankTeams(String[] votes) {
int n = votes[0].length();
int[][] cnt = new int[26][n + 1];
for (int i = 0; i < 26; i++) cnt[i][n] = i;
for (String vote : votes) {
for (int i = 0; i < n; i++) {
cnt[vote.charAt(i) - 'A'][i]--;
}
}
Character[] res = new Character[n];
for (int i = 0; i < n; i++) res[i] = votes[0].charAt(i);
Arrays.sort(res, (a, b) -> Arrays.compare(cnt[a - 'A'], cnt[b - 'A'])); // Java 9
StringBuilder ss = new StringBuilder();
for (char s : res) ss.append(s);
return ss.toString();
}
}