当前位置:网站首页>Sword finger offer 28. symmetric binary tree
Sword finger offer 28. symmetric binary tree
2022-07-26 02:12:00 【ThE wAlkIng D】
Title Description

Problem analysis
Ontology uses queues to do , First, judge whether the subtree is empty
Then put left and right , Determine whether the element of the queue is empty , Four conditions must be considered .
Then put the left side of the left subtree The right side of the right subtree is put into the queue in turn ( Put in pairs )
Code instance
class Solution {
public boolean isSymmetric(TreeNode root) {
Queue<TreeNode> deque = new LinkedList<>();
if(root == null){
return true;
}
deque.offer(root.left);
deque.offer(root.right);
while (!deque.isEmpty()) {
TreeNode leftNode = deque.poll();
TreeNode rightNode = deque.poll();
if (leftNode == null && rightNode == null) {
continue;
}// If all are empty, judge , Space symmetry continues
// if (leftNode == null && rightNode != null) {
// return false;
// }
// if (leftNode != null && rightNode == null) {
// return false;
// }
// if (leftNode.val != rightNode.val) {
// return false;
// }
// The above three judgment conditions are combined
if (leftNode == null || rightNode == null || leftNode.val != rightNode.val) {
return false;
}
// Here is the sequence and use Deque Different
deque.offer(leftNode.left);
deque.offer(rightNode.right);
deque.offer(leftNode.right);
deque.offer(rightNode.left);
}
return true;
}
}
边栏推荐
- BGP knowledge points summary
- A MCU event driven C framework
- 1205 Lock wait timeout exceeded; try restarting transaction处理
- js给页面添加随机像素噪声背景
- 18_请求文件
- opengauss如何手工安装(非OM方式)
- 由一个数据增量处理问题看到技术人员的意识差距
- 【2020】【论文笔记】磁控溅射法生长Bi2Te3/CoFeB双层异质结——
- A pluggable am335x industrial control module onboard WiFi module
- Bitmap这个“内存刺客”你要小心~
猜你喜欢

1. Mx6ul core module serial WiFi test (VIII)

本地仓库导致的报错

Ggplot2 learning summary

Adruino 基础实验学习(一)

What are the functions of cloud notes, and how do browsers add cloud note plug-ins

Worthington产气荚膜梭菌神经氨酸酶的特征及测定

What is the difference between for... In... And for... Of

BGP knowledge points summary

(CVPR 2019) GSPN: Generative Shape Proposal Network for 3D Instance Segmentation in Point Cloud

国标GB28181协议视频平台EasyGBS消息弹框模式优化
随机推荐
Quick start of adding, deleting, modifying and checking business
Design and driver transplantation of matrix keyboard circuit of Ti am335x industrial control module
DialogRPT-Dialog Ranking Pretrained Transformers
MPLS knowledge points
TI AM335x工控模块网络跟文件系统NFS的实现
Make and makefile summary II
I.MX6UL核心模块使用连载-RTC测试 (十二)
I.MX6UL核心模块使用连载-WIFI测试 (八)
Advantages of composition API
win下搭建嵌入式开发环境及frp穿透
还在用==0 null equal 判断空值吗,对isEmpty 和 isBlank有多少了解呢
微信小程序解密并拆包获取源码教程
1. Mx6ul core module uses serial can and buzzer test (XI)
BGP knowledge points summary
1. Mx6ul core module serial Ethernet test (VII)
HTC手机官解、S-ON/S-OFF与超级CID的关系
一款可插拔的AM335X工控模块板载wifi模块
Are you still using ==0 null equal to judge null values? How much do you know about isempty and isblank
1. Mx6ul core module serial use - touch screen calibration (IX)
2. Login - verification code function and saving login status