Skip to content

Commit 2486131

Browse files
authored
Merge pull request #1616 from a93a/169
Create 169-Majority-Element.kt
2 parents fd64b5a + f49c7a4 commit 2486131

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

kotlin/169-Majority-Element.kt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
3+
fun majorityElement(nums: IntArray): Int {
4+
var res = 0; var count = 0
5+
for(i in nums.indices){
6+
val found = nums[i]
7+
if(count == 0){
8+
res = found
9+
count++
10+
}else if(found == res)
11+
count++
12+
else
13+
count--
14+
}
15+
return res
16+
}
17+
}

0 commit comments

Comments
 (0)