Skip to content

Commit 2cd569f

Browse files
committed
169
1 parent 68efbd1 commit 2cd569f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

0001-500/Majority Element.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def majorityElement(self, nums: List[int]) -> int:
3+
candidate = None
4+
count = 0
5+
for num in nums:
6+
if count == 0:
7+
candidate = num
8+
count = 1
9+
elif num == candidate:
10+
count += 1
11+
else:
12+
count -= 1
13+
return candidate

0 commit comments

Comments
 (0)