Skip to content

Commit f49c7a4

Browse files
committed
169-Majority-Element.kt
1 parent 2e826d0 commit f49c7a4

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)