Skip to content

Commit

Permalink
majority element
Browse files Browse the repository at this point in the history
  • Loading branch information
sujin-sreekumaran committed Feb 2, 2024
1 parent 4966c51 commit 8a28f4d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions problems/Array/leetcode_169.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution:
def majorityElement(self, nums: List[int]) -> int:
res, count = 0, 0
for n in nums:
if count == 0:
res = n
count += (1 if n == res else -1)

return res

0 comments on commit 8a28f4d

Please sign in to comment.