lc-go/solutions/3/q300/solution.go

22 lines
489 B
Go

// Package q300 implements a solution for https://leetcode.com/problems/longest-increasing-subsequence/
package q300
func lengthOfLIS(nums []int) int {
maxSeqLen := make([]int, len(nums))
maxSeqLen[0] = 1
globalMax := 1
for i := 1; i < len(nums); i++ {
locMax := 0
for j := 0; j < i; j++ {
if nums[j] < nums[i] {
locMax = max(locMax, maxSeqLen[j])
}
}
maxSeqLen[i] = locMax + 1
globalMax = max(globalMax, maxSeqLen[i])
}
return globalMax
}
var _ = lengthOfLIS