We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
slices.Max
1 parent 5e0ab49 commit e40ddd5Copy full SHA for e40ddd5
problems/0337.打家劫舍III.md
@@ -477,14 +477,7 @@ func max(x, y int) int {
477
```go
478
func rob(root *TreeNode) int {
479
res := robTree(root)
480
- return max(res[0], res[1])
481
-}
482
-
483
-func max(a, b int) int {
484
- if a > b {
485
- return a
486
- }
487
- return b
+ return slices.Max(res)
488
}
489
490
func robTree(cur *TreeNode) []int {
@@ -498,7 +491,7 @@ func robTree(cur *TreeNode) []int {
498
491
// 考虑去偷当前的屋子
499
492
robCur := cur.Val + left[0] + right[0]
500
493
// 考虑不去偷当前的屋子
501
- notRobCur := max(left[0], left[1]) + max(right[0], right[1])
494
+ notRobCur := slices.Max(left) + slices.Max(right)
502
495
503
496
// 注意顺序:0:不偷,1:去偷
504
497
return []int{notRobCur, robCur}
0 commit comments