Skip to content

Commit cf96600

Browse files
authored
Merge pull request #1981 from alexprudhomme/0169-majority-element.cs
Create: 0169-majority-element.cs
2 parents 8c66e75 + 10beca8 commit cf96600

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

csharp/0169-majority-element.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Solution {
2+
public int MajorityElement(int[] nums) {
3+
int res = 0;
4+
int count = 0;
5+
6+
for(var i = 0; i < nums.Length; i ++){
7+
if (count == 0){
8+
res = nums[i];
9+
}
10+
count += (nums[i] == res) ? 1 : -1;
11+
}
12+
return res;
13+
}
14+
}

0 commit comments

Comments
 (0)