Skip to content

Commit f8c4a0d

Browse files
committed
Time: 1 ms (99.84%) | Memory: 48.1 MB (68.45%) - LeetSync
1 parent c4f746b commit f8c4a0d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int majorityElement(int[] num) {
3+
int major=num[0], count = 1;
4+
for(int i=1; i<num.length;i++){
5+
if(count==0){
6+
count++;
7+
major=num[i];
8+
}else if(major==num[i]){
9+
count++;
10+
}else count--;
11+
12+
}
13+
return major;
14+
}
15+
}

0 commit comments

Comments
 (0)