1234567891011121314151617181920 |
- func increasingTriplet(nums []int) bool {
- n := len(nums)
- if n < 3 {
- return false
- }
- st := []int{nums[0]}
- top := 0
- for i := 1; top < 2 && i < n; i++ {
- if num := nums[i]; st[top] < num {
- st = append(st, num)
- top++
- } else if num <= st[0] {
- st[0] = num
- } else {
- st[1] = num
- }
- }
- return top == 2
- }
|