mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 01:15:57 +08:00
26 lines
335 B
Go
26 lines
335 B
Go
package leetcode
|
|
|
|
import (
|
|
"math"
|
|
)
|
|
|
|
func thirdMax(nums []int) int {
|
|
a, b, c := math.MinInt64, math.MinInt64, math.MinInt64
|
|
for _, v := range nums {
|
|
if v > a {
|
|
c = b
|
|
b = a
|
|
a = v
|
|
} else if v < a && v > b {
|
|
c = b
|
|
b = v
|
|
} else if v < b && v > c {
|
|
c = v
|
|
}
|
|
}
|
|
if c == math.MinInt64 {
|
|
return a
|
|
}
|
|
return c
|
|
}
|