zoukankan      html  css  js  c++  java
  • 剑指 Offer 26. 树的子结构

     1 /**
     2  * Definition for a binary tree node.
     3  * struct TreeNode {
     4  *     int val;
     5  *     struct TreeNode *left;
     6  *     struct TreeNode *right;
     7  * };
     8  */
     9 
    10 bool isSubStructure2(struct TreeNode* A, struct TreeNode* B) {
    11     if (B == NULL) 
    12         return true;
    13     if (A == NULL)
    14         return false;
    15     if (A->val != B->val)
    16         return false;
    17     return isSubStructure2(A->left, B->left) && isSubStructure2(A->right, B->right);
    18  }
    19 
    20 bool isSubStructure(struct TreeNode* A, struct TreeNode* B){
    21     bool result =false;
    22     if (A && B) {
    23         if (A->val == B->val) {
    24             result = isSubStructure2(A, B);
    25         }
    26         if (result == false) {
    27             result = isSubStructure(A->left, B);
    28         }
    29         if (result == false) 
    30             result = isSubStructure(A->right, B);
    31     }
    32     return result;
    33 }
  • 相关阅读:
    scrapy框架
    selenium解析
    xpath解析
    解析语法
    request-html-render
    牛逼的requests-html
    Beautifulsoup
    请求和响应
    reuqests请求
    Django文件上传下载与富文本编辑框
  • 原文地址:https://www.cnblogs.com/micoblog/p/13748844.html
Copyright © 2011-2022 走看看