|
3 | 3 | importjava.util.Arrays; |
4 | 4 | importjava.util.Comparator; |
5 | 5 |
|
6 | | -/** |
7 | | - * 1366. Rank Teams by Votes |
8 | | - * |
9 | | - * In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition. |
10 | | - * The ordering of teams is decided by who received the most position-one votes. |
11 | | - * If two or more teams tie in the first position, we consider the second position to resolve the conflict, |
12 | | - * if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, |
13 | | - * we rank them alphabetically based on their team letter. |
14 | | - * Given an array of strings votes which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above. |
15 | | - * Return a string of all teams sorted by the ranking system. |
16 | | - * |
17 | | - * Example 1: |
18 | | - * Input: votes = ["ABC","ACB","ABC","ACB","ACB"] |
19 | | - * Output: "ACB" |
20 | | - * Explanation: Team A was ranked first place by 5 voters. No other team was voted as first place so team A is the first team. |
21 | | - * Team B was ranked second by 2 voters and was ranked third by 3 voters. |
22 | | - * Team C was ranked second by 3 voters and was ranked third by 2 voters. |
23 | | - * As most of the voters ranked C second, team C is the second team and team B is the third. |
24 | | - * |
25 | | - * Example 2: |
26 | | - * Input: votes = ["WXYZ","XYZW"] |
27 | | - * Output: "XWYZ" |
28 | | - * Explanation: X is the winner due to tie-breaking rule. |
29 | | - * X has same votes as W for the first position but X has one vote as second position while W doesn't have any votes as second position. |
30 | | - * |
31 | | - * Example 3: |
32 | | - * Input: votes = ["ZMNAGUEDSJYLBOPHRQICWFXTVK"] |
33 | | - * Output: "ZMNAGUEDSJYLBOPHRQICWFXTVK" |
34 | | - * Explanation: Only one voter so his votes are used for the ranking. |
35 | | - * |
36 | | - * Example 4: |
37 | | - * Input: votes = ["BCA","CAB","CBA","ABC","ACB","BAC"] |
38 | | - * Output: "ABC" |
39 | | - * Explanation: |
40 | | - * Team A was ranked first by 2 voters, second by 2 voters and third by 2 voters. |
41 | | - * Team B was ranked first by 2 voters, second by 2 voters and third by 2 voters. |
42 | | - * Team C was ranked first by 2 voters, second by 2 voters and third by 2 voters. |
43 | | - * There is a tie and we rank teams ascending by their IDs. |
44 | | - * |
45 | | - * Example 5: |
46 | | - * Input: votes = ["M","M","M","M"] |
47 | | - * Output: "M" |
48 | | - * Explanation: Only team M in the competition so it has the first rank. |
49 | | - * |
50 | | - * Constraints: |
51 | | - * 1 <= votes.length <= 1000 |
52 | | - * 1 <= votes[i].length <= 26 |
53 | | - * votes[i].length == votes[j].length for 0 <= i, j < votes.length. |
54 | | - * votes[i][j] is an English upper-case letter. |
55 | | - * All characters of votes[i] are unique. |
56 | | - * All the characters that occur in votes[0] also occur in votes[j] where 1 <= j < votes.length. |
57 | | - * */ |
58 | 6 | publicclass_1366 { |
59 | 7 | publicstaticclassSolution1 { |
60 | 8 | classNode { |
|