param { number [ ] [ ] } envelopes return { number } function maxEnvelopes ( envelopes ) { if ( ! Array . isArray ( envelopes ) || envelopes . length < 1 ) { return 0 ; } envelopes . sort ( ( a , b ) => a [ 0 ] === b [ 0 ] ? b [ 1 ] - a [ 1 ] : a [ 0 ] - b [ 0 ] ) ; let height = [ ] ; for ( let i in envelopes ) { height [ i ] = envelopes [ i ] [ 1 ] ; } return HeightLTS ( height ) ; } ; param { number [ ] } height return { number } function HeightLTS ( height ) { let count = 0 , len = height . length , queue = [ ] ; for ( let i = 0 ; i < len ; i ++ ) { let env = height [ i ] ; let left = 0 , right = count ; while ( left < right ) { let mid = left + Math . floor ( ( right - left ) / 2 ) ; if ( queue [ mid ] >= env ) { right = mid ; } else { left = mid + 1 ; } } if ( left === count ) count ++ ; queue [ left ] = env ; } return count ; } export { maxEnvelopes } ;