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 #497

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 4 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Nov 22, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
0337.打家劫舍III.md 使用 slices.Max 替代手工max func。
  • Loading branch information
gazeldx committed Nov 22, 2024
commit e40ddd5cbf46ae62a0b1aee4b683fb899b6fd6c8
11 changes: 2 additions & 9 deletions problems/0337.打家劫舍III.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,7 @@ func max(x, y int) int {
```go
func rob(root *TreeNode) int {
res := robTree(root)
return max(res[0], res[1])
}

func max(a, b int) int {
if a > b {
return a
}
return b
return slices.Max(res)
}

func robTree(cur *TreeNode) []int {
Expand All @@ -498,7 +491,7 @@ func robTree(cur *TreeNode) []int {
// 考虑去偷当前的屋子
robCur := cur.Val + left[0] + right[0]
// 考虑不去偷当前的屋子
notRobCur := max(left[0], left[1]) + max(right[0], right[1])
notRobCur := slices.Max(left) + slices.Max(right)

// 注意顺序:0:不偷,1:去偷
return []int{notRobCur, robCur}
Expand Down

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