mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
Merge branch 'master' of github.com:youngyangyang04/leetcode-master
This commit is contained in:
@ -379,6 +379,8 @@ class Solution {
|
||||
String targetLocation;
|
||||
//遍历从当前位置出发的机票
|
||||
for (int i = 0; i < targetLocations.size(); i++) {
|
||||
//去重,否则在最后一个测试用例中遇到循环时会无限递归
|
||||
if(i > 0 && targetLocations.get(i).equals(targetLocations.get(i - 1))) continue;
|
||||
targetLocation = targetLocations.get(i);
|
||||
//删除终点列表中当前的终点
|
||||
targetLocations.remove(i);
|
||||
@ -419,7 +421,6 @@ class Solution {
|
||||
```
|
||||
|
||||
### Python
|
||||
```
|
||||
回溯 使用字典
|
||||
```python
|
||||
class Solution:
|
||||
|
@ -405,6 +405,11 @@ class Heap {
|
||||
|
||||
// 获取堆顶元素并移除
|
||||
pop() {
|
||||
// 边界情况,只有一个元素或没有元素应直接弹出
|
||||
if (this.size() <= 1) {
|
||||
return this.queue.pop()
|
||||
}
|
||||
|
||||
// 堆顶元素
|
||||
const out = this.queue[0];
|
||||
|
||||
@ -416,7 +421,7 @@ class Heap {
|
||||
let left = 1; // left 是左子节点下标 left + 1 则是右子节点下标
|
||||
let searchChild = this.compare(left, left + 1) > 0 ? left + 1 : left;
|
||||
|
||||
while (searchChild !== undefined && this.compare(index, searchChild) > 0) { // 注意compare参数顺序
|
||||
while (this.compare(index, searchChild) > 0) { // 注意compare参数顺序
|
||||
[this.queue[index], this.queue[searchChild]] = [this.queue[searchChild], this.queue[index]];
|
||||
|
||||
// 更新下标
|
||||
@ -608,3 +613,4 @@ impl Solution {
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
@ -173,9 +173,9 @@ dp[j] 表示:填满j(包括j)这么大容积的包,有dp[j]种方法
|
||||
|
||||
* 已经有一个1(nums[i]) 的话,有 dp[4]种方法 凑成 容量为5的背包。
|
||||
* 已经有一个2(nums[i]) 的话,有 dp[3]种方法 凑成 容量为5的背包。
|
||||
* 已经有一个3(nums[i]) 的话,有 dp[2]中方法 凑成 容量为5的背包
|
||||
* 已经有一个4(nums[i]) 的话,有 dp[1]中方法 凑成 容量为5的背包
|
||||
* 已经有一个5 (nums[i])的话,有 dp[0]中方法 凑成 容量为5的背包
|
||||
* 已经有一个3(nums[i]) 的话,有 dp[2]种方法 凑成 容量为5的背包
|
||||
* 已经有一个4(nums[i]) 的话,有 dp[1]种方法 凑成 容量为5的背包
|
||||
* 已经有一个5 (nums[i])的话,有 dp[0]种方法 凑成 容量为5的背包
|
||||
|
||||
那么凑整dp[5]有多少方法呢,也就是把 所有的 dp[j - nums[i]] 累加起来。
|
||||
|
||||
|
Reference in New Issue
Block a user