Guest User

Untitled

a guest
Aug 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. String whoIsTheWinner(String votes[]){
  2. int maxCount = 0;
  3. int voteCount = 0;
  4. String winner = "";
  5. int i = 0;
  6. int j = 0;
  7. while(i <= votes.length-2){
  8. voteCount = 0;
  9. if(votes[i] != ""){
  10. j = i+1;
  11. while(j != votes.length-1){
  12. if(votes[i].equalsIgnoreCase(votes[j]) && votes[j]!=""){
  13. voteCount++;
  14. votes[j] = "";
  15. }
  16. j++;
  17. }
  18. }
  19. if(voteCount>maxCount){
  20. maxCount = voteCount;
  21. winner = votes[i];
  22. }
  23. votes[i] = "";
  24. i++;
  25. }
  26. return winner;
  27. }
Add Comment
Please, Sign In to add comment