Skip to content

Instantly share code, notes, and snippets.

@ashish173
Last active December 25, 2015 11:19
Show Gist options
  • Save ashish173/6968122 to your computer and use it in GitHub Desktop.
Save ashish173/6968122 to your computer and use it in GitHub Desktop.
voting algo my solution
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