Sword 39

https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/

找到数组后只能怪超过一半次数的数字,已经保证这个数的存在

设置一个 cnt 值维护 cur 的次数

如果 cur == num[i] cnt++

否则 cnt--

当 cnt == 0的时候将 cur 替换成 num[i]

原文地址:https://www.cnblogs.com/FriskyPuppy/p/14548011.html