AcWing 896. 最长上升子序列 II-golang
原题链接
中等
作者:
一只鱼
,
2021-03-20 15:48:07
,
所有人可见
,
阅读 307
最长上升子序列 II-golang
golang
package main
import (
"fmt"
"math"
)
var n int
var arr []int
var q []int
func main(){
fmt.Scanf("%d", &n)
arr = make([]int, n)
for i := 0; i < n; i++{
fmt.Scanf("%d", &arr[i])
}
q = make([]int, n+1)
for i := 0; i <= n ;i ++{
q[i] = math.MinInt32
}
var len int
var l, r int
for i := 0; i < n; i++{
l, r = 0, len
for l < r{
mid := (l+r+1) >>1
if q[mid] < arr[i]{
l = mid
}else{
r = mid - 1
}
}
q[r+1] = arr[i]
if r+1 > len{
len++
}
}
fmt.Println(len)
}
func max(a, b int)int{
if a > b{
return a
}
return b
}