AcWing 895. 最长上升子序列-golang
原题链接
简单
作者:
一只鱼
,
2021-03-20 00:41:38
,
所有人可见
,
阅读 176
最长上升子序列-golang
golang
package main
import "fmt"
var n int
var arr []int
var length []int
func main(){
fmt.Scanf("%d", &n)
length = make([]int, n)
arr = make([]int, n)
for i := 0; i < n; i++{
fmt.Scanf("%d", &arr[i])
}
for i := 0; i < n; i++{
length[i] = 1
for j := 0; j < i; j++{
if arr[j] < arr[i]{
length[i] = max(length[i], length[j]+1)
}
}
}
var maxLen = -1
for i := 0; i < n; i++{
maxLen = max(maxLen, length[i])
}
fmt.Println(maxLen)
}
func max(a, b int)int{
if a > b{
return a
}
return b
}