当前位置:网站首页>Sword finger offer 28 Symmetric binary tree
Sword finger offer 28 Symmetric binary tree
2022-07-03 14:22:00 【anieoo】
Original link : The finger of the sword Offer 28. Symmetric binary tree
solution:
class Solution {
public:
bool isSymmetric(TreeNode* root) {
if(root == NULL) return true;
return dfs(root->left,root->right);
}
bool dfs(TreeNode *left, TreeNode *right) {
if(left == NULL && right == NULL) return true;
else if((left != NULL && right == NULL) || (left == NULL && right != NULL)) return false;
if(left->val != right->val) return false;
return dfs(left->left,right->right) && dfs(left->right, right->left);
}
};
边栏推荐
猜你喜欢

JS matrix zero

Exercise 6-1 classify and count the number of characters

Leetcode (4) -- find the median of two positively ordered arrays

Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?

protobuf与grpc

Print. JS -- web page file printing

JS first summary

好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions

如何查询淘宝天猫的宝贝类目
随机推荐
Simulated access
一文了解微分段应用场景与实现机制
Exercise 10-1 calculate the sum of 1 to n using recursive functions
The mail function of LNMP environment cannot send mail
Leetcode(4)——尋找兩個正序數組的中比特數
How to bold text in AI
Understand the application scenario and implementation mechanism of differential segment
C language,%d% Difference between 2D%2d%02d
愉悦资本新双币基金近40亿元完成首次关账
GRPC的四种数据流以及案例
How Facebook moves instagram from AWS to its own server
Redis:字符串类型数据的操作命令
Jiuyi cloud black free encryption free version source code
7-7 12-24 hour system
MongoDB数据库入门的常用命令
Exercise 8-8 moving letters
Recent learning summary
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Canvas utility library fabric JS user manual
6-9 statistics of single digits (15 points)