C++ 2line recursion solution


  • 0
    M
    class Solution {
    public:
        int findTilt(TreeNode* root) {
            return root?abs(sum(root->left)-sum(root->right))+findTilt(root->left)+findTilt(root->right):0;
        }
    
        int sum(TreeNode* root) {
            return root?root->val+sum(root->left)+sum(root->right):0;
        }
    };
    

Log in to reply
 

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