Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String whoIsTheWinner(String votes[]){
- int maxCount = 0;
- int voteCount = 0;
- String winner = "";
- int i = 0;
- int j = 0;
- while(i <= votes.length-2){
- voteCount = 0;
- if(votes[i] != ""){
- j = i+1;
- while(j != votes.length-1){
- if(votes[i].equalsIgnoreCase(votes[j]) && votes[j]!=""){
- voteCount++;
- votes[j] = "";
- }
- j++;
- }
- }
- if(voteCount>maxCount){
- maxCount = voteCount;
- winner = votes[i];
- }
- votes[i] = "";
- i++;
- }
- return winner;
- }
Add Comment
Please, Sign In to add comment