1 Star 3 Fork 5

刘炜/python LeetCode

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
0169多数元素.py 353 Bytes
Copy Edit Raw Blame History
刘炜 authored 2020-03-13 08:19 +08:00 . 哈希表
class Solution:
def majorityElement(self, nums: List[int]) -> int:
numdict = {}
for num in nums:
if num in numdict.keys():
numdict[num] += 1
else:
numdict[num] = 1
for key, value in numdict.items():
if numdict[key] > len(nums)//2:
return key
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/new_way/python-LeetCode.git
git@gitee.com:new_way/python-LeetCode.git
new_way
python-LeetCode
python LeetCode
master

Search