Last active
December 25, 2015 11:19
-
-
Save ashish173/6968122 to your computer and use it in GitHub Desktop.
voting algo my solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int[] count = new int[cast.length]; // cast array is votes casted | |
int count1, num; | |
for(int i=0; i<cast.length; i++) { | |
num = ++count[cast[i]]; // increments count on vote cast in array | |
if(num > cast.length/2) { | |
System.out.println("Winner is candidate " + cast[i]); // returns the index of winner | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment