Skip to content

Commit cacc4aa

Browse files
refactor 229
1 parent ef2f0ce commit cacc4aa

File tree

1 file changed

+4
-20
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-20
lines changed

src/main/java/com/fishercoder/solutions/_229.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,14 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/**
7-
* 229. Majority Element II
8-
*
9-
* Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.
10-
* The algorithm should run in linear time and in O(1) space.
11-
*
12-
* Example 1:
13-
* Input: [3,2,3]
14-
* Output: [3]
15-
*
16-
* Example 2:
17-
* Input: [1,1,1,3,3,2,2,2]
18-
* Output: [1,2]
19-
20-
Hint:
21-
How many majority elements could it possibly have?
22-
Do you have a better hint? Suggest it!
23-
*/
246
public class _229 {
257

268
public static class Solution1 {
27-
/**Moore Voting algorithm:
9+
/**
10+
* Moore Voting algorithm:
2811
* This is an extension of Majority Element I, instead of one one majority, there could be a max of two majority elements,
29-
* so we'll just use two counters to do the job.*/
12+
* so we'll just use two counters to do the job.
13+
*/
3014
public List<Integer> majorityElement(int[] nums) {
3115
List<Integer> result = new ArrayList<>();
3216
if (nums == null || nums.length == 0) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy