Increasing Triplet Subsequence
題目說明
輸入一個數列nums,如果該數列存在一個三元組(i, j, k)符合"i < j < k而且nums[i] < nums[j] < nums[k]",則輸出1,否則輸出0。
這一題的解答不需要使用雙重迴圈(nested loops)。
本題類似LeetCode 334
輸入格式
數列長度k,以及該數列的內容共k個數字
輸入值範圍
2 <= k <= 10000,其他數字皆大於等於-10000且小於等於10000。
sample input 1
5 1 2 3 4 5
sample output 1
1
說明
因為該數列中任三個數都是合法的三元組
sample input 2
5 5 4 3 2 1
sample output 2
0
說明
因為該數列中任三個數都不是合法的三元組
sample input 3
6 2 1 5 0 4 6
sample output 3
1
說明
因為nums[3] == 0 < nums[4] == 4 < nums[5] == 6.
Comments