leetcode 404. Sum of Left Leaves

    int sumOfLeftLeaves(TreeNode* root) {
        if (root == NULL)
            return 0;
        
        int sum = 0;
        if (root->left && root->left->left == NULL && root->left->right == NULL)
            sum += root->left->val;
        
        int l = sumOfLeftLeaves(root->left);
        int r = sumOfLeftLeaves(root->right);
        return sum + l + r;
    }

 

posted on 2018-02-11 16:14  willaty  阅读(75)  评论(0编辑  收藏  举报

导航