mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-29 23:23:42 +08:00
规范格式
This commit is contained in:
27
leetcode/0404.Sum-of-Left-Leaves/404. Sum of Left Leaves.go
Normal file
27
leetcode/0404.Sum-of-Left-Leaves/404. Sum of Left Leaves.go
Normal file
@ -0,0 +1,27 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
)
|
||||
|
||||
// TreeNode define
|
||||
type TreeNode = structures.TreeNode
|
||||
|
||||
/**
|
||||
* Definition for a binary tree node.
|
||||
* type TreeNode struct {
|
||||
* Val int
|
||||
* Left *TreeNode
|
||||
* Right *TreeNode
|
||||
* }
|
||||
*/
|
||||
|
||||
func sumOfLeftLeaves(root *TreeNode) int {
|
||||
if root == nil {
|
||||
return 0
|
||||
}
|
||||
if root.Left != nil && root.Left.Left == nil && root.Left.Right == nil {
|
||||
return root.Left.Val + sumOfLeftLeaves(root.Right)
|
||||
}
|
||||
return sumOfLeftLeaves(root.Left) + sumOfLeftLeaves(root.Right)
|
||||
}
|
Reference in New Issue
Block a user