From b02e144d7a865a632db2bd025291c00f8583ee96 Mon Sep 17 00:00:00 2001 From: ironartisan Date: Wed, 11 Aug 2021 20:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B00116.=E5=A1=AB=E5=85=85?= =?UTF-8?q?=E6=AF=8F=E4=B8=AA=E8=8A=82=E7=82=B9=E7=9A=84=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=8F=B3=E4=BE=A7=E8=8A=82=E7=82=B9=E6=8C=87=E9=92=88?= =?UTF-8?q?java=E6=B3=A8=E9=87=8A=E5=8F=8A=E4=BB=A3=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...个节点的下一个右侧节点指针.md | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/problems/0116.填充每个节点的下一个右侧节点指针.md b/problems/0116.填充每个节点的下一个右侧节点指针.md index 8b816f5e..34c666f3 100644 --- a/problems/0116.填充每个节点的下一个右侧节点指针.md +++ b/problems/0116.填充每个节点的下一个右侧节点指针.md @@ -133,14 +133,14 @@ public: // 递归法 class Solution { public void traversal(Node cur) { - if(cur == null) return; - if(cur.left != null) cur.left.next = cur.right; - if(cur.right != null){ - if(cur.next != null) cur.right.next = cur.next.left; + if (cur == null) return; + if (cur.left != null) cur.left.next = cur.right; // 操作1 + if (cur.right != null) { + if(cur.next != null) cur.right.next = cur.next.left; //操作2 else cur.right.next = null; } - traversal(cur.left); - traversal(cur.right); + traversal(cur.left); // 左 + traversal(cur.right); //右 } public Node connect(Node root) { traversal(root); @@ -152,26 +152,26 @@ class Solution { // 迭代法 class Solution { public Node connect(Node root) { - if(root == null) return root; + if (root == null) return root; Queue que = new LinkedList(); que.offer(root); Node nodePre = null; Node node = null; - while(!que.isEmpty()){ + while (!que.isEmpty()) { int size = que.size(); - for(int i=0; i