From eaa8414c670fa7e68763a95aa9f5cd18478ff23a Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Tue, 30 Apr 2024 17:11:48 +0100 Subject: [PATCH] Solve 169. Majority Element --- python/169_majority_element.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 python/169_majority_element.py diff --git a/python/169_majority_element.py b/python/169_majority_element.py new file mode 100644 index 0000000..4637adf --- /dev/null +++ b/python/169_majority_element.py @@ -0,0 +1,3 @@ +class Solution: + def majorityElement(self, nums: List[int]) -> int: + return max(Counter(nums).items(), key=lambda k: k[1])[0]