标签:nbsp 依次 subject lag 出现 根据 class 等于 utf-8
# -*- coding:utf-8 -*- class Solution: def MoreThanHalfNum_Solution(self, numbers): if (numbers is None or len(numbers) == 0): return 0 current = numbers[0] flag = 1 for i in numbers[1:]: if (i != current): flag -= 1 else: flag += 1 if (flag == 0): current = i flag = 1 if (flag >= 1): count = 0 for i in numbers: if (current == i): count += 1 if (count > len(numbers)//2): return current return 0
标签:nbsp 依次 subject lag 出现 根据 class 等于 utf-8
原文地址:https://www.cnblogs.com/tianqizhi/p/9784061.html