|
| 1 | +{ |
| 2 | + "problem_name": "majority_element", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "169", |
| 5 | + "problem_title": "Majority Element", |
| 6 | + "difficulty": "Easy", |
| 7 | + "topics": "Array, Hash Table, Divide and Conquer, Sorting, Counting", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "Given an array `nums` of size `n`, return the majority element.\n\nThe majority element is the element that appears more than `\u230an / 2\u230b` times. You may assume that the majority element always exists in the array.", |
| 10 | + "readme_examples": [ |
| 11 | + { "content": "```\nInput: nums = [3,2,3]\nOutput: 3\n```" }, |
| 12 | + { "content": "```\nInput: nums = [2,2,1,1,1,2,2]\nOutput: 2\n```" } |
| 13 | + ], |
| 14 | + "readme_constraints": "- n == nums.length\n- 1 <= n <= 5 * 10^4\n- -10^9 <= nums[i] <= 10^9", |
| 15 | + "readme_additional": "**Follow-up:** Could you solve the problem in linear time and in O(1) space?", |
| 16 | + "solution_imports": "", |
| 17 | + "solution_methods": [ |
| 18 | + { |
| 19 | + "name": "majority_element", |
| 20 | + "parameters": "nums: list[int]", |
| 21 | + "return_type": "int", |
| 22 | + "dummy_return": "0" |
| 23 | + } |
| 24 | + ], |
| 25 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution", |
| 26 | + "test_class_name": "MajorityElement", |
| 27 | + "test_helper_methods": [ |
| 28 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 29 | + ], |
| 30 | + "test_methods": [ |
| 31 | + { |
| 32 | + "name": "test_majority_element", |
| 33 | + "parametrize": "nums, expected", |
| 34 | + "parametrize_typed": "nums: list[int], expected: int", |
| 35 | + "test_cases": "[([3,2,3], 3), ([2,2,1,1,1,2,2], 2), ([1], 1), ([1,1,2], 1), ([2,2,2,1,1], 2)]", |
| 36 | + "body": "result = self.solution.majority_element(nums)\nassert result == expected" |
| 37 | + } |
| 38 | + ], |
| 39 | + "playground_imports": "from solution import Solution", |
| 40 | + "playground_test_case": "# Example test case\nnums = [3,2,3]\nexpected = 3", |
| 41 | + "playground_execution": "result = Solution().majority_element(nums)\nresult", |
| 42 | + "playground_assertion": "assert result == expected" |
| 43 | +} |
0 commit comments