当前位置:网站首页>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);
}
};
边栏推荐
- Learn to punch in today
- Stop asking yourself if you are suitable for software testing
- JS Part III
- PCB中常用快捷键
- Solr series of full-text search engines - basic principles of full-text search
- Redis: operation command of string type data
- Leetcode(4)——寻找两个正序数组的中位数
- The mail function of LNMP environment cannot send mail
- Solve the problem of dormitory router campus network sharing login
- Redis:字符串類型數據的操作命令
猜你喜欢
Global event bus
[clean up the extraordinary image of Disk C]
concat和concat_ws()区别及group_concat()和repeat()函数的使用
Doris学习笔记之数据表的创建
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
Leetcode(4)——尋找兩個正序數組的中比特數
7-11 calculation of residential water charges by sections
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取
Exercise 7-6 count capital consonants
随机推荐
全文检索引擎Solr系列—–全文检索基本原理
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
Exercise 7-6 count capital consonants
NPM install is stuck with various strange errors of node NPY
7-2 and then what time (15 minutes)
Although not necessarily the best, it must be the hardest!
Article content typesetting and code highlighting
7-16 find the set of integers that meet the given conditions
7-7 12-24 hour system
C language,%d% Difference between 2D%2d%02d
如何查询淘宝天猫的宝贝类目
Solr series of full-text search engines - basic principles of full-text search
Raft 协议
7-4 BCD decryption (10 points)
Fabric. JS document
Jiuyi cloud black free encryption free version source code
Why is this error reported when modifying records in the database
Too many files with unapproved license
Convert string to decimal integer
关于回溯问题中的排列问题的思考(LeetCode46题与47题)