Skip to content

Commit 739f263

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ba76ab1 commit 739f263

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
+10-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
22
PROBLEM : Find majority element in the given array.
33
4-
PROBLEM DESCRIPTION :
4+
PROBLEM DESCRIPTION :
55
Given a array of elements of size n.
66
The majority element is the element that appears more than [n/2] times.
77
We assume that the majority element is always exists in the array.
88
9-
EXAMPLE :
9+
EXAMPLE :
1010
input : array = [1,3,5,1,1]
1111
output : 1
1212
explanation : 1 appears three times in array which is greater than [n/2] i.e [5/2] = 2.
@@ -15,20 +15,21 @@
1515
- In an array of elements of size n there exists only one element that appears greater than [n/2] times.
1616
1717
- If we sort the given elements in the array the [n/2] element in the array must be the majority element.
18-
if we sort [1,3,5,1,1] it will be [1,1,1,3,5]
18+
if we sort [1,3,5,1,1] it will be [1,1,1,3,5]
1919
element present in the [n/2] index of the sorted array is majority element i.e 1 where n is size of array.
2020
"""
2121

2222

23-
#function to find majority element
24-
def majority_element(array:list)->int:
25-
'''
23+
# function to find majority element
24+
def majority_element(array: list) -> int:
25+
"""
2626
Return majority element in the list.
27-
'''
27+
"""
2828
array.sort()
29-
return array[len(array)//2]
29+
return array[len(array) // 2]
3030

3131

3232
if __name__ == "__main__":
3333
import doctest
34-
doctest.testmod()
34+
35+
doctest.testmod()

0 commit comments

Comments
 (0)