problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::subtree_of_another_tree::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static bool equal (TreeNode *tn1, TreeNode *tn2)
 
static bool isSubtree (TreeNode *root, TreeNode *subRoot)
 

详细描述

在文件 leetcode.h2364 行定义.

成员函数说明

◆ equal()

bool leetcode::subtree_of_another_tree::Solution::equal ( TreeNode tn1,
TreeNode tn2 
)
static

在文件 leetcode.cpp6298 行定义.

6298 {
6299 if(static_cast<int>(tn1 == nullptr) + static_cast<int>(tn2 == nullptr) == 1) {
6300 return false;
6301 }
6302 if(tn1 == nullptr && tn2 == nullptr) {
6303 return true;
6304 }
6305 if(tn1->val != tn2->val) {
6306 return false;
6307 }
6308 if(static_cast<int>(tn1->left == nullptr) + static_cast<int>(tn2->left == nullptr) == 1) {
6309 return false;
6310 }
6311 if(static_cast<int>(tn1->right == nullptr) + static_cast<int>(tn2->right == nullptr) == 1) {
6312 return false;
6313 }
6314 return equal(tn1->left, tn2->left) && equal(tn1->right, tn2->right);
6315 }
static bool equal(TreeNode *tn1, TreeNode *tn2)
Definition: leetcode.cpp:6298

引用了 equal(), leetcode::TreeNode::left, leetcode::TreeNode::right , 以及 leetcode::TreeNode::val.

被这些函数引用 equal() , 以及 isSubtree().

◆ isSubtree()

bool leetcode::subtree_of_another_tree::Solution::isSubtree ( TreeNode root,
TreeNode subRoot 
)
static

在文件 leetcode.cpp6276 行定义.

6276 {
6277 if(root == nullptr) {
6278 return false;
6279 }
6280 queue<TreeNode *> q;
6281 q.push(root);
6282 while(!q.empty()) {
6283 auto *const node = q.front();
6284 q.pop();
6285 if(equal(node, subRoot)) {
6286 return true;
6287 }
6288 if(node->left != nullptr) {
6289 q.push(node->left);
6290 }
6291 if(node->right != nullptr) {
6292 q.push(node->right);
6293 }
6294 }
6295 return false;
6296 }
vector< int > root
Definition: acwing408.cpp:349

引用了 equal() , 以及 acwing::acwing836_408::root.


该类的文档由以下文件生成: