Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 6 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions problems/0198.打家劫舍.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,24 @@ function rob(nums: number[]): number {
};
```

Rust:

```rust
impl Solution {
pub fn rob(nums: Vec<i32>) -> i32 {
if nums.len() == 1 {
return nums[0];
}
let mut dp = vec![0; nums.len()];
dp[0] = nums[0];
dp[1] = nums[0].max(nums[1]);
for i in 2..nums.len() {
dp[i] = (dp[i - 2] + nums[i]).max(dp[i - 1]);
}
dp[nums.len() - 1]
}
}
```


<p align="center">
Expand Down
27 changes: 26 additions & 1 deletion problems/0257.二叉树的所有路径.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ public:

```Java
//解法一

//方式一
class Solution {
/**
* 递归法
Expand Down Expand Up @@ -428,9 +430,32 @@ class Solution {
}
}
}

//方式二
class Solution {

List<String> result = new ArrayList<>();

public List<String> binaryTreePaths(TreeNode root) {
deal(root, "");
return result;
}

public void deal(TreeNode node, String s) {
if (node == null)
return;
if (node.left == null && node.right == null) {
result.add(new StringBuilder(s).append(node.val).toString());
return;
}
String tmp = new StringBuilder(s).append(node.val).append("->").toString();
deal(node.left, tmp);
deal(node.right, tmp);
}
}
```
```java
// 解法2
// 解法二
class Solution {
/**
* 迭代法
Expand Down
8 changes: 6 additions & 2 deletions problems/0279.完全平方数.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,19 @@ class Solution {
for (int j = 0; j <= n; j++) {
dp[j] = max;
}
//如果不想要寫for-loop填充數組的話,也可以用JAVA內建的Arrays.fill()函數。
//Arrays.fill(dp, Integer.MAX_VALUE);

//当和为0时,组合的个数为0
dp[0] = 0;
// 遍历物品
for (int i = 1; i * i <= n; i++) {
// 遍历背包
for (int j = i * i; j <= n; j++) {
if (dp[j - i * i] != max) {
//if (dp[j - i * i] != max) {
dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
}
//}
//不需要這個if statement,因爲在完全平方數這一題不會有"湊不成"的狀況發生( 一定可以用"1"來組成任何一個n),故comment掉這個if statement。
}
}
return dp[n];
Expand Down

AltStyle によって変換されたページ (->オリジナル) /