I did it once, but I can't remember.
1Now set an X, record the smallest of the three numbers, Y record the middle one, initialize X is nums[0],y is Integer.max_value .2 3 then start looking back from 1:4 51. If this number is larger than Y, because this time x <y, if you find a third that is larger than Y, then return true6 72If this number is not larger than Y, there are two things:8 91) is smaller than x (or equal to x), the x is updated to the current position, but Y does not move, X is the minimum number of potentially next set, Y still indicates that the second number, if the next group found greater than Y, can still return true. Ten One2no smaller than x, that is, between the current X and Y, then the update y,x unchanged, indicating that a group of XY failed. Why this must be found, because the X is already updated first (because the X is updated in 2.1), less than the original is less than X, Y (because the condition 2 illustrates this), so this is a smaller set of XY, more likely to succeed. A -If the end of the entire array of traversal has not found the answer, then return false
That's probably it. Hope to remember!!
1 Public BooleanIncreasingtriplet (int[] nums) {2 if(Nums.length < 3) {3 return false;4 }5 intx = nums[0];6 inty =Integer.max_value;7 for(inti = 1; i < nums.length; i++) {8 if(Nums[i] >y) {9 return true;Ten}Else { One if(Nums[i] <=x) { Ax =Nums[i]; -}Else { -y =Nums[i]; the } - } - } - return false; +}
Time complexity is O (n)
334. Increasing Triplet subsequence