Skip to content

Commit d4fe69a

Browse files
Time: 4 ms (67.95%), Space: 56.1 MB (51.02%) - LeetHub
1 parent 4eebc46 commit d4fe69a

File tree

1 file changed

+18
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)