Skip to content

Commit e2890a5

Browse files
authored
Update 334-increasing-triplet-subsequence.js
1 parent 44a4231 commit e2890a5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

334-increasing-triplet-subsequence.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,26 @@ const increasingTriplet = function(nums) {
1212
}
1313
return false;
1414
};
15+
16+
// another
17+
18+
/**
19+
* @param {number[]} nums
20+
* @return {boolean}
21+
*/
22+
const increasingTriplet = function(nums) {
23+
const n = nums.length, stk = []
24+
for(let e of nums) {
25+
let l = 0, r = stk.length
26+
while(l < r) {
27+
const mid = l + Math.floor((r - l) / 2)
28+
if (e > stk[mid]) l = mid + 1
29+
else r = mid
30+
}
31+
32+
stk[l] = e
33+
if(stk.length > 2) return true
34+
}
35+
36+
return false
37+
};

0 commit comments

Comments
 (0)