Majority Element 2021-06-16 20:17

Problem Description

public int majorityElement(int[] nums) {
    int count = 0;
    int curVote = 0;
    for (int n : nums) {
        if (count == 0) {
            curVote = n;
        }
        count = count + (curVote == n ? 1 : -1);
    }
    return curVote;
}
Runtime Memory
1 ms 45.4 MB

henryxi leetcode list

EOF