共计 340 个字符,预计需要花费 1 分钟才能阅读完成。
leetcode 链接:
https://leetcode.cn/problems/longest-increasing-subsequence/s…
解题思路:
动静布局
func lengthOfLIS(nums []int) int {if len(nums) < 1 {return 0}
dp := make([]int, len(nums))
result := 1
for i := 0; i < len(nums); i++ {dp[i] = 1
for j := 0; j < i; j++ {if nums[j] < nums[i] {dp[i] = max(dp[j]+1, dp[i])
}
}
result = max(result, dp[i])
}
return result
}
func max(a, b int) int {
if a > b {return a}
return b
}
正文完