Add solution 1668、1669、1670、1672、1673

This commit is contained in:
YDZ
2020-12-16 03:08:19 +08:00
parent 2e796fe70e
commit e85f3236f4
30 changed files with 1266 additions and 428 deletions

View File

@ -0,0 +1,13 @@
package leetcode
// 单调栈
func mostCompetitive(nums []int, k int) []int {
stack := make([]int, 0, len(nums))
for i := 0; i < len(nums); i++ {
for len(stack)+len(nums)-i > k && len(stack) > 0 && nums[i] < stack[len(stack)-1] {
stack = stack[:len(stack)-1]
}
stack = append(stack, nums[i])
}
return stack[:k]
}