Skip to content

Latest commit

 

History

History
18 lines (17 loc) · 641 Bytes

树代码.md

File metadata and controls

18 lines (17 loc) · 641 Bytes
class Solution {
public:
    int sumOfLeftLeaves(TreeNode* root) {
        if (root == NULL) return 0;
        int sum = 0;
        if (root->left != NULL && root->left->left == NULL && root->left->right == NULL) {
            sum = root->left->val;
        }
        return sum + sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);
    }
};

作者:carlsun-2
链接:https://leetcode-cn.com/problems/sum-of-left-leaves/solution/404-zuo-xie-zi-zhi-he-di-gui-yu-fei-di-gui-fang-fa/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。