当前位置:网站首页>[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
边栏推荐
- Preliminary analysis of Airbase
- Two Stage Detection
- [leetcode refers to offer 32 - III. print binary tree III from top to bottom (medium)]
- wait、waitpid
- Common problems in deploying projects with laravel and composer for PHP
- 3-5 obtaining cookies through XSS and the use of XSS background management system
- 41. 缺失的第一个正数
- 3-5通过XSS获取cookie以及XSS后台管理系统的使用
- Deno 1.13.2 发布
- ROS学习笔记-----ROS的使用教程
猜你喜欢
ROS learning notes - tutorial on the use of ROS
Common problems in deploying projects with laravel and composer for PHP
Sharpness difference (SD) calculation method of image reconstruction and generation domain index
Lunch on the 23rd day at home
MySQL基础之写表(创建表)
Keywords static, extern + global and local variables
Amazon and epic will be settled, and the Microsoft application mall will be opened to third parties
3-5 obtaining cookies through XSS and the use of XSS background management system
CUDA, NVIDIA driver, cudnn download address and version correspondence
C, print the source program of beautiful bell triangle
随机推荐
Yolov5 NMS source code understanding
Keywords static, extern + global and local variables
airbase 初步分析
Automatic heap dump using MBean
Mysql database common sense storage engine
Some thoughts on super in pytorch, combined with code
Problem brushing plan -- dynamic programming (IV)
Graph traversal - BFS, DFS
ros功能包内自定义消息引用失败
41. The first missing positive number
居家第二十三天的午饭
Linux中,MySQL的常用命令
Introduction to tensorrt
Rust更适合经验较少的程序员?
笔记本电脑卡顿怎么办?教你一键重装系统让电脑“复活”
Minecraft 1.12.2模组开发(四十三) 自定义盾牌(Shield)
100天拿下11K,转岗测试的超全学习指南
IOT design and development
Tensorflow1. X and 2 How does x read those parameters saved in CKPT
C# 知识