229. Majority Element II Medium
1/**
2 * [229] Majority Element II
3 *
4 * Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.
5 *
6 * Example 1:
7 *
8 * Input: nums = [3,2,3]
9 * Output: [3]
10 *
11 * Example 2:
12 *
13 * Input: nums = [1]
14 * Output: [1]
15 *
16 * Example 3:
17 *
18 * Input: nums = [1,2]
19 * Output: [1,2]
20 *
21 *
22 * Constraints:
23 *
24 * 1 <= nums.length <= 5 * 10^4
25 * -10^9 <= nums[i] <= 10^9
26 *
27 *
28 * Follow up: Could you solve the problem in linear time and in O(1) space?
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/majority-element-ii/
34// discuss: https://leetcode.com/problems/majority-element-ii/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn majority_element(nums: Vec<i32>) -> Vec<i32> {
40 vec![]
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_229() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.