zoukankan      html  css  js  c++  java
  • 572. Subtree of Another Tree

    /**
     * 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 isSubtree(TreeNode* s, TreeNode* t) {
            if (isSameTree(s, t))   return true;
            if (s == NULL || t == NULL) return false;
            return isSubtree(s->left, t) || isSubtree(s->right, t);
        }
        bool isSameTree(TreeNode* s, TreeNode* t) {
            if (s == t) return true;
            if (s == NULL || t == NULL || t->val != s->val) return false;
            return isSameTree(s->left, t->left) && isSameTree(s->right, t->right);
        }
    };
  • 相关阅读:
    MQ
    redis
    MongoDB
    进程相关命令
    catalina.sh
    tomcat-jvm
    中间件简介
    websphere
    mysql
    shell变量与字符串操作
  • 原文地址:https://www.cnblogs.com/JTechRoad/p/9110527.html
Copyright © 2011-2022 走看看