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]

posted on 2021-03-17 10:43  FriskyPuppy  阅读(25)  评论(0编辑  收藏  举报

导航