404. Sum of Left Leaves

2018-04-16  本文已影响16人  安东可

404. Sum of Left Leaves
[思路]


    int sumOfLeftLeaves(TreeNode* root) {
        if(! root)return 0;
        int sum =0;
        sum += sumofleft(root->left,true);
        sum +=sumofleft(root->right,false);
        return sum;

           
    }
    
    int sumofleft(TreeNode* root, bool left){
        if(!root) return 0;
        
        if(! root->left && !root->right && left)
            return root->val;
        
        return sumofleft(root->left,true) + sumofleft(root->right,false);
        
        
    }


上一篇下一篇

猜你喜欢

热点阅读