Solved LeetCode program · 989 of 1,000
#1366 · Rank Teams by Votes
Original English source
Keep a shared alphabet as empty text. Place "ABCDEFGHIJKLMNOPQRSTUVWXYZ" into alphabet. Keep a shared width of 0. Keep a shared last of 0. Keep a shared counts as an empty list of whole numbers. Keep a shared teams as an empty list of whole numbers. Keep a shared used as an empty list of whole numbers. Keep a shared index of 0. Keep a shared wanted as empty text. Keep a shared earlier of 0. Keep a shared best of 0.
The votes is a list of "ABC", "ACB", "ABC", "ACB", and "ACB". The firstvote is item 0 of votes. Set last to the last position of firstvote. Set width to last plus 1.
For every cell from 0 to 676 minus 1.
Place 0 into counts.
To locate. The spot is 0.
Repeat while spot is at most 25.
If the slice of alphabet from spot to spot plus 1 matches wanted, set index to spot, return. Add 1 to spot.
For each vote in votes.
The spot is 0.
Repeat while spot is less than width.
The symbol is the slice of vote from spot to spot plus 1. Set wanted to symbol. Locate. Increase item (index times width plus spot) of counts by 1. Add 1 to spot.
For every spot from 0 to width minus 1.
The symbol is the slice of firstvote from spot to spot plus 1. Set wanted to symbol. Locate. Place index into teams.
For every spot from 0 to 25.
Place 0 into used.
To compare with first (a whole number) and second (a whole number). Set earlier to 0. If first is less than second, set earlier to 1. The spot is 0.
Repeat while spot is less than width.
The one is item (first times width plus spot) of counts. The two is item (second times width plus spot) of counts. If one is more than two, set earlier to 1, return. If one is less than two, set earlier to 0, return. Add 1 to spot.
To consider with candidate (a whole number). If item candidate of used is 1, return. If best is less than 0, set best to candidate, return. Compare with candidate and best. If earlier is 1, set best to candidate.
To choose. Set best to -1.
For each candidate in teams.
Consider with candidate.
The order is an empty list of whole numbers.
For every slot from 0 to width minus 1.
Choose. Set item best of used to 1. Place best into order.
The line is empty text.
For each choice in order.
The symbol is the slice of alphabet from choice to choice plus 1. Place symbol into line.
Show line.
Expected stdout
ACB