一道中等难度。读完就有思路结果做了一天。
In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition.
The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, 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, we rank them alphabetically based on their team letter.
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.
Return a string of all teams sorted by the ranking system.
Example 1:
Input: votes = ["ABC","ACB","ABC","ACB","ACB"]
Output: "ACB"
题目是要求 投票以后根据票数多少 进行再次排序。 比如A B两个如果选A做首选的多 那么A在前面 反之则B在前,
如果选他们为首选的人一样多。那么再比较选他们两个做第二选择的人的多少。以此类推。都相同就按字母顺序排序
这道题目看完我就有了两个想法
凡是这样的字母表的 一般都会用一个 int[26]的数组来计数。 比用dictionary还清爽
比较的规则看起来是递归了
于是动手写代码。结果犯了n次数组越界。 我的天。。。。 越界到怀疑人生。
最后虽然accept了 但是一天过去了。 我一点都不高兴。应该总结点儿什么了
In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition.
The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, 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, we rank them alphabetically based on their team letter.
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.
Return a string of all teams sorted by the ranking system.
Example 1:
Input: votes = ["ABC","ACB","ABC","ACB","ACB"]
Output: "ACB"
题目是要求 投票以后根据票数多少 进行再次排序。 比如A B两个如果选A做首选的多 那么A在前面 反之则B在前,
如果选他们为首选的人一样多。那么再比较选他们两个做第二选择的人的多少。以此类推。都相同就按字母顺序排序
这道题目看完我就有了两个想法
凡是这样的字母表的 一般都会用一个 int[26]的数组来计数。 比用dictionary还清爽
比较的规则看起来是递归了
于是动手写代码。结果犯了n次数组越界。 我的天。。。。 越界到怀疑人生。
最后虽然accept了 但是一天过去了。 我一点都不高兴。应该总结点儿什么了