mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-25 12:14:26 +08:00
Add solution 1668、1669、1670、1672、1673
This commit is contained in:
@ -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]
|
||||
}
|
Reference in New Issue
Block a user