Class Solution

java.lang.Object
g0201_0300.s0229_majority_element_ii.Solution

public class Solution extends Object
229 - Majority Element II.<p>Medium</p> <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>\u230a n/3 \u230b</code> times.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,2,3]</p> <p><strong>Output:</strong> [3]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1]</p> <p><strong>Output:</strong> [1]</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [1,2]</p> <p><strong>Output:</strong> [1,2]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 5 * 10<sup>4</sup></code></li> <li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> </ul> <p><strong>Follow up:</strong> Could you solve the problem in linear time and in <code>O(1)</code> space?</p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • majorityElement

      public List<Integer> majorityElement(int[] nums)