mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 16:47:55 +00:00
14 lines
643 B
JavaScript
14 lines
643 B
JavaScript
const loadBisectLeft=(()=>{let cache;return()=>cache||(cache=import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm').then(({bisectLeft})=>bisectLeft));})();
|
|
export async function findLISLength(nums){
|
|
if(!Array.isArray(nums)) throw new TypeError('Expected an array');
|
|
if(!nums.length) return 0;
|
|
const bisectLeft=await loadBisectLeft();
|
|
const tails=[];
|
|
for(const value of nums){
|
|
if(!Number.isFinite(value)) throw new TypeError('Array must contain only finite numbers');
|
|
const index=bisectLeft(tails,value,0,tails.length);
|
|
tails[index]=value;
|
|
}
|
|
return tails.length;
|
|
}
|
|
export default findLISLength; |