Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public int majorityElement(int[] nums) {
- int count=0, ret = 0;
- for (int num: nums) {
- if (count==0)
- ret = num;
- if (num!=ret)
- count--;
- else
- count++;
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement