-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.js
36 lines (33 loc) · 861 Bytes
/
solution.js
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
29
30
31
32
33
34
35
36
/**
* @param {number[]} nums
* @return {boolean}
*/
var increasingTriplet = function (nums) {
let first = Infinity, second = Infinity;
for (let i = 0; i < nums.length; i++) {
if (nums[i] <= first) {
first = nums[i];
} else if (nums[i] <= second) {
second = nums[i];
} else {
return true;
}
}
return false;
};
// var increasingTriplet = function (nums) {
// let minToRight = [], maxToLeft = [];
// for (let i = 0; i < nums.length; i++) {
// minToRight[i] = Math.min((minToRight[i - 1] ?? Infinity), nums[i])
// }
//
// for (let i = nums.length - 1; i >= 0; i--) {
// maxToLeft[i] = Math.max((maxToLeft[i + 1] ?? -Infinity), nums[i])
// }
//
// for (let i = 0; i < nums.length; i++) {
// if (minToRight[i] < nums[i] && nums[i] < maxToLeft[i]) return true;
// }
//
// return false;
// };