C++ easy and clean soluion


  • 4
    M
        int res=0;
        int findTilt(TreeNode* root) {
            DFS(root);
            return res;
        }
        
        int DFS(TreeNode* n) {
            if(n==NULL) return 0;
            int l=DFS(n->left);
            int r=DFS(n->right);
            res+=abs(l-r);
            return l+r+n->val;
        }

  • 0
    G

    Nice solution!


Log in to reply
 

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