| https://leetcode.com/problems/third-maximum-number | Easy |
|---|
class Solution {
fun thirdMax(nums: IntArray): Int {
var a = Long.MIN_VALUE
var b = Long.MIN_VALUE
var c = Long.MIN_VALUE
for (v in nums) {
val x = v.toLong()
if (x == a || x == b || x == c) continue
if (x > a) {
c = b
b = a
a = x
} else if (x > b) {
c = b
b = x
} else if (x > c) {
c = x
}
}
return if (c == Long.MIN_VALUE) a.toInt() else c.toInt()
}
}