c++ iterative solution


  • 0
    T
    class Solution {
    public:
        int sumOfLeftLeaves(TreeNode* root) {
            if (!root) return 0;
            return (root->left && !root->left->left && !root->left->right? root->left->val:0) 
                + sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.