A very short C (very clean)


  • 0
    P
    #define ISCHILD(root) ((root)!=NULL && ((root)->left == NULL) && ((root)->right == NULL)) 
    int sumOfLeftLeaves(struct TreeNode* root) {
        if(root == NULL) return 0;
        return (ISCHILD(root->left) ? root->left->val : 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.