标签:sel info iter mic 去重 print focus http lis
list转set:set(list)
set转list:list(set)
注:list转set时会自动去重!
法一:[ int(i) for i in digits ]
法二:map( int, digits )
法一:[ str(i) for i in digits]
法二:map( str, digits )
注:法二语法:map(function,iterable,…)
1 class Solution(object): 2 def majorityElement(self, nums): 3 """ 4 :type nums: List[int] 5 :rtype: int 6 """ 7 # 转set去重 8 setnum = set(nums) 9 for i in setnum: 10 if nums.count(i) > int(len(nums) / 2): 11 return i 12 13 14 if __name__ == ‘__main__‘: 15 solution = Solution() 16 print(solution.majorityElement([3, 2, 3]))
标签:sel info iter mic 去重 print focus http lis
原文地址:https://www.cnblogs.com/panweiwei/p/12748798.html