MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/Majority Element/solution1.py:1–10  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution:
2 def majorityElement(self, nums: List[int]) -> int:
3 #we make a set of the given list
4 s=list(set(nums))
5 #iterate over the set
6 for i in range(len(s)):
7 #we check if the count of the element is >n/2 by using the count function as soon as we get that required element which satisfies the condition we break out the loop and return the value to the main function.
8 if nums.count(s[i])>len(nums)/2:
9 break
10 return s[i]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected