var increasingTriplet = function (nums) { const len = nums.length;
constLMin = []; constRMax = [];
LMin[0] = nums[0]; for (let index = 1; index < nums.length; index++) { const element = nums[index]; LMin[index] = Math.min(LMin[index - 1], element); }
RMax[len - 1] = nums[len - 1]; for (let index = len - 2; index >= 0; index--) { const element = nums[index]; RMax[index] = Math.max(RMax[index + 1], element); }
for (let index = 0; index < nums.length; index++) { const element = nums[index]; if (element > LMin[index] && element < RMax[index]) { returntrue; } } returnfalse; };
关键 2:贪心 思路 2:初始设置 first = nums[0];second = 无穷大;现在循环找 third
若 third > second,则找到了,返回 true
若 third < second 但 third > first,则 second = third,继续循环找 third
若 third < first,则 first = third,继续循环找 third(虽然 first 在 second 之后了,但在 second 之前,存在过老的 first 并小于 second)