function getArray(num) {
let res = [0]
let p = num.slice()
for(let i = 0; i < num.length; i++) {
if(num[i] < num[res[res.length - 1]]) {
p[i] = res[res.length - 1]
res.push(i)
} else {
let left = 0, right = res.length
while(left < right) {
const mid = left + (right - left >> 1)
if(num[res[mid]] < num[i]) {
left = mid + 1
} else {
right = mid
}
}
if(num[res[left]] > num[i]) {
res[left] = i
if(left > 0) {
p[i] = left - 1
}
}
}
}
let u = res.length, v = res[u]
while(u--) {
res[u] = v
v = p[v]
}
return res.map(i => num[i])
}
Vue3 实现最长递增子序列方法
于 2024-07-17 15:09:13 首次发布