Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. public class Solution {
  2. public int majorityElement(int[] nums) {
  3. int count=0, ret = 0;
  4. for (int num: nums) {
  5. if (count==0)
  6. ret = num;
  7.  
  8. if (num!=ret)
  9. count--;
  10. else
  11. count++;
  12. }
  13. return ret;
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement