Skip to content

Commit 1ca1314

Browse files
authored
Create rank-teams-by-votes.py
1 parent 2d10c37 commit 1ca1314

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Python/rank-teams-by-votes.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Time: O(m * (n + mlogm)), n is the number of votes
2+
# , m is the length of vote
3+
# Space: O(m^2)
4+
5+
class Solution(object):
6+
def rankTeams(self, votes):
7+
"""
8+
:type votes: List[str]
9+
:rtype: str
10+
"""
11+
count = {v: [0]*len(votes[0]) + [v] for v in votes[0]}
12+
for vote in votes:
13+
for i, v in enumerate(vote):
14+
count[v][i] -= 1
15+
return "".join(sorted(votes[0], key=count.__getitem__))

0 commit comments

Comments
 (0)