题解 | #数组中出现次数超过一半的数字#
数组中出现次数超过一半的数字
https://www.nowcoder.com/practice/e8a1b01a2df14cb2b228b30ee6a92163?tpId=295&tqId=23271&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D295
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param numbers int整型一维数组 # @return int整型 # class Solution: def MoreThanHalfNum_Solution(self , numbers: List[int]) -> int: # write code here length = len(numbers) list1 = list(set(numbers)) L1=[] for x in list1: L1.append([x,numbers.count(x)]) L1.sort(key=lambda x:x[1],reverse=True) return (L1[0][0])