Skip to content

Commit 8384b12

Browse files
author
hieu
committed
Solve Problem 169 - Majority Element
1 parent 143ad44 commit 8384b12

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package array;
2+
3+
public class Problem169_MajorityElement {
4+
public int majorityElement(int[] A) {
5+
int res = 0, count = 0;
6+
for (int a : A) {
7+
if (count == 0) res = a;
8+
if (a == res) count++;
9+
else count--;
10+
}
11+
return res;
12+
}
13+
}

0 commit comments

Comments
 (0)