4 Star 25 Fork 17

编程语言算法集 / Go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
longestincreasingsubsequence.go 577 Bytes
一键复制 编辑 原始数据 按行查看 历史
package dynamic
import (
"github.com/TheAlgorithms/Go/math/max"
)
// LongestIncreasingSubsequence returns the longest increasing subsequence
// where all elements of the subsequence are sorted in increasing order
func LongestIncreasingSubsequence(elements []int) int {
n := len(elements)
lis := make([]int, n)
for i := range lis {
lis[i] = 1
}
for i := range lis {
for j := 0; j < i; j++ {
if elements[i] > elements[j] && lis[i] < lis[j]+1 {
lis[i] = lis[j] + 1
}
}
}
res := 0
for _, value := range lis {
res = max.Int(res, value)
}
return res
}
Go
1
https://gitee.com/TheAlgorithms/Go.git
git@gitee.com:TheAlgorithms/Go.git
TheAlgorithms
Go
Go
master

搜索帮助