当前位置:网站首页>[leetcode sword finger offer 28. Symmetric binary tree (simple)]
[leetcode sword finger offer 28. Symmetric binary tree (simple)]
2022-04-23 21:20:00 【Minaldo7】
subject :
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
The problem solving process :
Copy a root node , Then compare the left branch with the right branch .
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */
class Solution {
public boolean isSymmetric(TreeNode root) {
return dfs(root, root);
}
public boolean dfs(TreeNode root1, TreeNode root2){
if(root1 == null && root2 == null) return true;
if(root1 == null || root2 == null) return false;
if(root1.val == root2.val)
return dfs(root1.left,root2.right) && dfs(root1.right,root2.left);
return false;
}
}
Execution results :
版权声明
本文为[Minaldo7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/111/202204210544479611.html
边栏推荐
- setInterval、setTimeout、requestAnimationFrame
- Win 11K in 100 days, super complete learning guide for job transfer test
- Pytorch: runtimeerror: an attempt has been made to start a new process Error reporting (resolved)
- MySQL基础之写表(创建表)
- Tensorflow1. X and 2 How does x read those parameters saved in CKPT
- Two Stage Detection
- 常用60类图表使用场景、制作工具推荐
- Some thoughts on super in pytorch, combined with code
- Introduce structured concurrency and release swift 5.5!
猜你喜欢
Rust更适合经验较少的程序员?
电脑越用越慢怎么办?文件误删除恢复方法
Win 11K in 100 days, super complete learning guide for job transfer test
Graph traversal - BFS, DFS
Reentrant function
Addition, deletion, modification and query of advanced MySQL data (DML)
wait、waitpid
常用60类图表使用场景、制作工具推荐
Prim、Kruskal
How to make Jenkins job run automatically after startup
随机推荐
go reflect
一些接地气的话儿
Thinkphp5 + data large screen display effect
一文解决浏览器跨域问题
Valueerror: invalid literal for int() with base 10 conversion error related to data type
Normalized transforms in pytorch The real calculation process of normalize
Deep analysis of C language function
IOT design and development
Opencv application -- jigsaw puzzle
Norm normalization in tensorflow and pytorch of records
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
Use 3080ti to run tensorflow GPU = 1 X version of the source code
ROS learning notes - tutorial on the use of ROS
Pytorch selects the first k maximum (minimum) values and their indexes in the data
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ‘:app:stripDe
中创存储|想要一个好用的分布式存储云盘,到底该怎么选
Lunch on the 23rd day at home
Detectron2 usage model
ros功能包内自定义消息引用失败
Preliminary analysis of Airbase