Skip to content

Commit 58437eb

Browse files
committed
Merge branches 'master' and 'master' of github.com:flames519/leetcode-master
2 parents 18a37ec + 5043002 commit 58437eb

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

problems/0045.跳跃游戏II.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ func jump(nums []int) int {
208208
}
209209
return dp[len(nums)-1]
210210
}
211+
```
212+
213+
Javascript:
214+
```Javascript
215+
var jump = function(nums) {
216+
let curIndex = 0
217+
let nextIndex = 0
218+
let steps = 0
219+
for(let i = 0; i < nums.length - 1; i++) {
220+
nextIndex = Math.max(nums[i] + i, nextIndex)
221+
if(i === curIndex) {
222+
curIndex = nextIndex
223+
steps++
224+
}
225+
}
226+
227+
return steps
228+
};
229+
```
230+
211231
/*
212232
dp[i]表示从起点到当前位置的最小跳跃次数
213233
dp[i]=min(dp[j]+1,dp[i]) 表示从j位置用一步跳跃到当前位置,这个j位置可能有很多个,却最小一个就可以

problems/0239.滑动窗口最大值.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,36 @@ Python:
267267

268268
Go:
269269

270+
```go
271+
func maxSlidingWindow(nums []int, k int) []int {
272+
var queue []int
273+
var rtn []int
274+
275+
for f := 0; f < len(nums); f++ {
276+
//维持队列递减, 将 k 插入合适的位置, queue中 <=k 的 元素都不可能是窗口中的最大值, 直接弹出
277+
for len(queue) > 0 && nums[f] > nums[queue[len(queue)-1]] {
278+
queue = queue[:len(queue)-1]
279+
}
280+
// 等大的后来者也应入队
281+
if len(queue) == 0 || nums[f] <= nums[queue[len(queue)-1]] {
282+
queue = append(queue, f)
283+
}
284+
285+
if f >= k - 1 {
286+
rtn = append(rtn, nums[queue[0]])
287+
//弹出离开窗口的队首
288+
if f - k + 1 == queue[0] {
289+
queue = queue[1:]
290+
}
291+
}
292+
}
293+
294+
return rtn
295+
296+
}
297+
298+
```
299+
270300
Javascript:
271301
```javascript
272302
var maxSlidingWindow = function (nums, k) {

problems/背包理论基础01背包-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
dp[j]为 容量为j的背包所背的最大价值,那么如何推导dp[j]呢?
5757

58-
dp[j]可以通过dp[j - weight[j]]推导出来,dp[j - weight[i]]表示容量为j - weight[i]的背包所背的最大价值。
58+
dp[j]可以通过dp[j - weight[i]]推导出来,dp[j - weight[i]]表示容量为j - weight[i]的背包所背的最大价值。
5959

6060
dp[j - weight[i]] + value[i] 表示 容量为 j - 物品i重量 的背包 加上 物品i的价值。(也就是容量为j的背包,放入物品i了之后的价值即:dp[j]
6161

0 commit comments

Comments
 (0)