Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcacc4aa

Browse files
refactor 229
1 parentef2f0ce commitcacc4aa

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
importjava.util.ArrayList;
44
importjava.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
publicclass_229 {
257

268
publicstaticclassSolution1 {
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
publicList<Integer>majorityElement(int[]nums) {
3115
List<Integer>result =newArrayList<>();
3216
if (nums ==null ||nums.length ==0) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp