> For the complete documentation index, see [llms.txt](https://blog.yushunchen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.yushunchen.com/algo/array/third-maximum-number.md).

# Third Maximum Number

{% embed url="<https://leetcode.com/problems/third-maximum-number/>" %}

## Solution 1

```go
import "math"

func thirdMax(nums []int) int {
    firstMax, secondMax, thirdMax := math.MinInt64, math.MinInt64, math.MinInt64
    for _, v := range nums {
        if v > firstMax {
            thirdMax = secondMax
            secondMax = firstMax
            firstMax = v
        } else if v > secondMax && v < firstMax {
            thirdMax = secondMax
            secondMax = v
        } else if v > thirdMax && v < secondMax {
            thirdMax = v
        }
    }
    if thirdMax == math.MinInt64 {
        return firstMax
    }
    return thirdMax
}
```
