This commit is contained in:
2026-07-23 16:56:50 +08:00
parent 124ad9afdf
commit 92784ffb0f
36 changed files with 2015 additions and 608 deletions
+51
View File
@@ -0,0 +1,51 @@
package top100liked
import (
"testing"
)
// https://leetcode.cn/problems/longest-increasing-subsequence/?envType=study-plan-v2&envId=top-100-liked
// 300. 最长递增子序列
//
// 给你一个整数数组 `nums` ,找到其中最长严格递增子序列的长度。
// 子序列 是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,`[3,6,2,7]` 是数组 `[0,3,1,6,2,2,7]` 的子序列。
// 示例 1
// 输入:nums = [10,9,2,5,3,7,101,18]
// 输出:4
// 解释:最长递增子序列是 [2,3,7,101],因此长度为 4 。
// 示例 2
// 输入:nums = [0,1,0,3,2,3]
// 输出:4
// 示例 3
// 输入:nums = [7,7,7,7,7,7,7]
// 输出:1
//
// 提示:
// - `1 <= nums.length <= 2500`
// - `-10^4 <= nums[i] <= 10^4`
// 进阶:
// - 你能将算法的时间复杂度降低到 `O(n log(n))` 吗?
//
func lengthOfLIS(nums []int) int {
}
func TestLengthOfLIS(t *testing.T) {
cases := []struct {
name string
nums []int
want int
}{
{"example1", []int{10, 9, 2, 5, 3, 7, 101, 18}, 4},
{"example2", []int{0, 1, 0, 3, 2, 3}, 4},
{"example3", []int{7, 7, 7, 7, 7, 7, 7}, 1},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := lengthOfLIS(c.nums)
if got != c.want {
t.Errorf("got %v, want %v", got, c.want)
}
})
}
}