[C++]Two 2-line recursive functions solution


  • 0
    L
    class Solution {
    public:
        int findTilt(TreeNode* root) {
            if(!root) return 0;
            return findTilt(root->left)+findTilt(root->right)+abs(nodeSum(root->left)-nodeSum(root->right));
        }
        int nodeSum(TreeNode* root){
            if(!root) return 0;
            return root->val+nodeSum(root->left)+nodeSum(root->right);
        }
    };
    

Log in to reply
 

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