-
Notifications
You must be signed in to change notification settings - Fork 70
/
res.ts
28 lines (24 loc) · 771 Bytes
/
res.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function increasingTriplet(nums: number[]): boolean {
if (nums.length < 3) {
return false;
}
let currentLMinNum = Number.MAX_SAFE_INTEGER;
const lMin = nums.map((num) => {
currentLMinNum = num < currentLMinNum ? num : currentLMinNum;
return currentLMinNum;
});
let currentMaxNum = Number.MIN_SAFE_INTEGER;
const rMax = new Array(nums.length);
for (let i = nums.length-1; i >= 0; i--) {
currentMaxNum = nums[i] > currentMaxNum ? nums[i] : currentMaxNum;
rMax[i] = currentMaxNum;
}
let result = false;
for (let i = 1; i < nums.length-1; i++) {
if (lMin[i-1] < nums[i] && nums[i] < rMax[i+1]) {
result = true;
break;
}
}
return result;
};