Skip to content

Commit

Permalink
Create: 0169-majority-element.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme committed Jan 9, 2023
1 parent fa2d4c3 commit 10beca8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions csharp/0169-majority-element.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Solution {
public int MajorityElement(int[] nums) {
int res = 0;
int count = 0;

for(var i = 0; i < nums.Length; i ++){
if (count == 0){
res = nums[i];
}
count += (nums[i] == res) ? 1 : -1;
}
return res;
}
}

0 comments on commit 10beca8

Please sign in to comment.