当前位置:网站首页>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);
}
};
边栏推荐
- Onmenusharetimeline custom shared content is invalid, and the title and icon are not displayed
- 分布式事务(Seata) 四大模式详解
- 7-7 12-24 hour system
- Current situation, analysis and prediction of information and innovation industry
- SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
- JS Part 2
- 7-9 find a small ball with a balance
- JS Part III
- 修改数据库中的记录为什么报这个错
- [clean up the extraordinary image of Disk C]
猜你喜欢
Programming language: the essence of type system
FPGA test method takes mentor tool as an example
如何查询淘宝天猫的宝贝类目
Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
[clean up the extraordinary image of Disk C]
Page generation QR code
npm install卡住与node-npy的各种奇怪报错
JS Part 2
Generate directories from web content
随机推荐
[Jilin University] information sharing of postgraduate entrance examination and re examination
别再问自己适不适合做软件测试了
如何查询淘宝天猫的宝贝类目
Stop asking yourself if you are suitable for software testing
Solr series of full-text search engines - basic principles of full-text search
Selective sorting
虽然不一定最优秀,但一定是最努力的!
X86 assembly language - Notes from real mode to protected mode
Ultra simple mobile map development
7-15 calculation of PI
Leetcode(4)——尋找兩個正序數組的中比特數
2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
剑指 Offer 28. 对称的二叉树
Exercise 8-8 moving letters
Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
The mail function of LNMP environment cannot send mail
7-10 calculate salary
Message subscription and publishing
JVM object lifecycle
Find specified characters