update project structure

This commit is contained in:
2024-06-20 06:29:07 +08:00
parent 17b4ef8970
commit fdaa94a0fa
49 changed files with 35 additions and 4 deletions

16
leetcode_py/169.py Normal file
View File

@@ -0,0 +1,16 @@
# Majority Elements
# the majority elements will appears more than half times
# Use Boyer-Moore Voting Alogrithm
class Solution:
def majorityElements(self, nums: list[int]) -> int:
count = 0
candidate = None
for num in nums:
if count == 0:
candidate = num
count += 1 if num == candidate else -1
return candidate