topic:
Given an unsorted array, the array is determined whether or not there is increasing subsequence length of 3.
Mathematical expressions are as follows:
If there is such i, j, k, and satisfies ≤ 0 I < J < K ≤ n- -1,
such ARR [I] < ARR [J] < ARR [K] , returns true; otherwise returns false.
Description: The time requirements of the algorithm complexity is O ( n- ), the spatial complexity is O ( . 1 ).
Example 1:
Input: [1,2,3,4,5] Output: true
Example 2:
Input: [5,4,3,2,1] Output: false
Problem solving:
class Solution { public Boolean increasingTriplet ( int [] the nums) { IF (nums.length <. 3 ) return to false ; // define two pointers int min = Integer.MAX_VALUE; // minimum value of a first number of int MID = Integer .MAX_VALUE; // intermediate numbers for ( int I = 0; I <nums.length; I ++ ) { IF (the nums [I] <= min) { min = the nums [I]; } the else IF (the nums [I] < = MID) { mid = the nums [i]; // later when the mid is assigned, in front proved that i mid value smaller than the present, and this is the mid value larger than the minimum min of a } the else { return to true ; // then when there larger than the number of mid, specify the presence of increasing sequence number of three } } return to false ; } }