Skip to content

Commit 3a120df

Browse files
Update 300. 最长递增子序列.md
1 parent 6c977df commit 3a120df

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Dynamic Programming/300. 最长递增子序列.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,26 @@ class Solution {
9292
}
9393
```
9494

95+
96+
97+
Go 语言:
98+
99+
```go
100+
func lengthOfLIS(nums []int) int {
101+
dp := make([]int, len(nums))
102+
dp[0] = 1
103+
res := dp[0]
104+
for i := 1; i < len(nums); i++ {
105+
maxn := 0
106+
for j := 0; j < i; j++ {
107+
if nums[i] > nums[j] {
108+
maxn = max(maxn, dp[j])
109+
}
110+
}
111+
dp[i] = maxn + 1
112+
res = max(res, dp[i])
113+
}
114+
return res
115+
}
116+
```
117+

0 commit comments

Comments
 (0)