C++ 4ms solution with simple 12 line code

  • 2
    class Solution {
      bool isSymmetric(TreeNode* root) {
          if(!root) return true;
          return dfs(root->left, root->right);
      bool dfs(TreeNode *treel, TreeNode *treer){
        if(!(treel&&treer)) return treel==treer;
        if(!(treel->val == treer->val)) return false; 
        return dfs(treel->left, treer->right)&&dfs(treel->right, treer->left);

Log in to reply

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