2-liner C++ (if squeezed..)

  • 0
        bool isSubtree(TreeNode* s, TreeNode* t) {        
            return s and (sameTree(s,t) or isSubtree(s->left,t) or isSubtree(s->right,t));
        bool sameTree(TreeNode* s, TreeNode* t) {
            return !s? !t : t and s->val == t->val and sameTree(s->left,t->left) and sameTree(t->right,s->right);

Log in to reply

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