Simple C++ Recursive solution (6ms)

  • 0
    class Solution {
        int helper(TreeNode *root, bool left) {
            if (!root) return 0;
            else if (!root->left && !root->right) return (left) ? root->val : 0;
            else return helper(root->left, true) + helper(root->right, false);
        int sumOfLeftLeaves(TreeNode* root) {
            return helper(root, false);

Log in to reply

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