https://leetcode.com/problems/majority-element Easy

Решение

class Solution {
    fun majorityElement(nums: IntArray): Int {
        var cand = 0
        var cnt = 0
        for (v in nums) {
            if (cnt == 0) {
                cand = v
                cnt = 1
            } else if (v == cand) {
                cnt++
            } else {
                cnt--
            }
        }
        return cand
    }
}