classSolution{public:boolincreasingTriplet(vector<int>&nums){intnum1=INT_MAX;// Setting it to very big number, to compare it with our array elementsintnum2=INT_MAX;// Setting it to very big number, to compare it with our array elements// Pick each element from left to rightfor(intcurrentNumber:nums){// Case 1: `currentNumber` <= `num1`if(currentNumber<=num1){num1=currentNumber;// Set `currentNumber` to `num1`}// Case 1: `currentNumber` >= `num1` and `currentNumber` <= `num2`elseif(currentNumber<=num2){num2=currentNumber;// Set `currentNumber` to `num2`}// Case 3: `currentNumber` >= `num1` and `num2`else{returntrue;// If `currentNumber` is >= `num1` and `num2`. // We found a bigger number of our triplet}}returnfalse;// If, we do not reach till `Case 3` it means there is no triplet subsequence }};
Warning
LINK
You are about to visit a link which has been flagged with the above content warnings. Do you wish to continue?