/*
* @lc app=leetcode.cn id=334 lang=typescript
*
* [334] 递增的三元子序列
*/
// @lc code=start
function increasingTriplet(nums: number[]): boolean {}
// @lc code=end
function increasingTriplet(nums: number[]): boolean {
const stack: number[] = []
for (const num of nums) {
let i = stack.length
while (i > 0 && stack[i - 1] >= num) i--
stack[i] = num
if (stack.length > 2) return true
}
return false
}
test.each([
{ input: { nums: [1, 1, 1, 1, 1, 1, 1] }, output: false },
{ input: { nums: [1, 2, 3, 4, 5] }, output: true },
{ input: { nums: [5, 4, 3, 2, 1] }, output: false },
{ input: { nums: [2, 1, 5, 0, 4, 6] }, output: true },
])('input: nums = $input.nums', ({ input: { nums }, output }) => {
expect(increasingTriplet(nums)).toEqual(output)
})