Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1616 from a93a/169
Browse files Browse the repository at this point in the history
Create 169-Majority-Element.kt
  • Loading branch information
Ahmad-A0 committed Dec 29, 2022
2 parents fd64b5a + f49c7a4 commit 2486131
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions kotlin/169-Majority-Element.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {

fun majorityElement(nums: IntArray): Int {
var res = 0; var count = 0
for(i in nums.indices){
val found = nums[i]
if(count == 0){
res = found
count++
}else if(found == res)
count++
else
count--
}
return res
}
}

0 comments on commit 2486131

Please sign in to comment.