Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1981 from alexprudhomme/0169-majority-…
Browse files Browse the repository at this point in the history
…element.cs

Create: 0169-majority-element.cs
  • Loading branch information
tahsintunan authored Jan 10, 2023
2 parents 8c66e75 + 10beca8 commit cf96600
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 cf96600

Please sign in to comment.