zoukankan      html  css  js  c++  java
  • Leetcode 101

    /**
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     TreeNode *left;
     *     TreeNode *right;
     *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     * };
     */
    class Solution {
    public:
        bool isSymmetric(TreeNode* root) {
            if(root == NULL)
                return true;
            return DFS(root->left,root->right);
        }
        
        bool DFS(TreeNode* rtl,TreeNode* rtr){ //这样写法也是各种二叉树DFS的一种很好的写法
            if((!rtl)&&(!rtr)) return true;  // 和上面平衡二叉树写法类似
            if((rtl&&!rtr)||(!rtl&&rtr)||rtl->val != rtr->val) return false;
            return DFS(rtl->left,rtr->right)&&DFS(rtl->right,rtr->left);
        }
    };
  • 相关阅读:
    mongoose pre
    socket2
    golang (10 语法)
    golang(7 方法重写)
    npm安装git上的包
    npm 配置
    npm v3版本
    npm v2版本
    awk oneline
    sed oneline
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10318958.html
Copyright © 2011-2022 走看看