当前位置:网站首页>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);
}
};
边栏推荐
- Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
- Redis: commandes d'action pour les données de type chaîne
- Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
- Invalid Z-index problem
- JS matrix zero
- Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?
- Programming language: the essence of type system
- Jiuyi cloud black free encryption free version source code
- Understand the application scenario and implementation mechanism of differential segment
- Reflection -- basic usage
猜你喜欢
Exercise 10-2 recursive factorial sum
Mysql多表查询 #子查询
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
Leetcode(4)——尋找兩個正序數組的中比特數
Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?
Why is this error reported when modifying records in the database
Exercise 9-1 time conversion
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
JS matrix zero
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
随机推荐
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
Raft 协议
js . Find the first palindrome string in the array
分布式事务(Seata) 四大模式详解
添加Zabbix计算类型项目Calculated items
Global event bus
Duet date picker (time plug-in that can manually enter the date)
7-6 mixed type data format input
How to bold text in AI
How Facebook moves instagram from AWS to its own server
Find the sum of the elements of each row of the matrix
Common mixins
Accelerating strategy learning using parallel differentiable simulation
JVM object lifecycle
Solution to failure or slow downloading of electron when electron uses electron builder to package
7-20 print 99 formula table (format output)
[clean up the extraordinary image of Disk C]
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
Message subscription and publishing
7-10 calculate salary