diff --git a/notes/剑指 offer 题解.md b/notes/剑指 offer 题解.md index 7fdef7de..10976409 100644 --- a/notes/剑指 offer 题解.md +++ b/notes/剑指 offer 题解.md @@ -1040,7 +1040,7 @@ public ListNode ReverseList(ListNode head) { ## 题目描述 -

+

## 解题思路 @@ -1400,21 +1400,21 @@ private void dfs(TreeNode node, int target, ArrayList path) { 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的 head。 -

+

## 解题思路 第一步,在每个节点的后面插入复制的节点。 -

+

第二步,对复制节点的 random 链接进行赋值。 -

+

第三步,拆分。 -

+

```java public RandomListNode Clone(RandomListNode pHead) { @@ -1456,7 +1456,7 @@ public RandomListNode Clone(RandomListNode pHead) { 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。 -

+

## 解题思路 @@ -2046,13 +2046,7 @@ private void merge(int[] nums, int first, int mid, int last) { ## 题目描述 -```html -A: a1 → a2 - ↘ - c1 → c2 → c3 - ↗ -B: b1 → b2 → b3 -``` +

## 解题思路 @@ -2148,6 +2142,8 @@ private void inOrder(TreeNode root, int k) { 从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 +

+ ## 解题思路 ```java @@ -2161,10 +2157,10 @@ public int TreeDepth(TreeNode root) { ## 题目描述 -

- 平衡二叉树左右子树高度差不超过 1。 +

+ ## 解题思路 ```java @@ -2559,18 +2555,11 @@ public int StrToInt(String str) { # 68. 树中两个节点的最低公共祖先 -## 二叉查找树 +## 解题思路 -```html - _______6______ - / \ - ___2__ ___8__ - / \ / \ - 0 4 7 9 - / \ - 3 5 -For example, the lowest common ancestor (LCA) of nodes 2 and 8 is 6. Another example is LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition. -``` +### 二叉查找树 + +

```java public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { @@ -2580,18 +2569,9 @@ public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { } ``` -## 普通二叉树 +### 普通二叉树 -```html - _______3______ - / \ - ___5__ ___1__ - / \ / \ - 6 2 0 8 - / \ - 7 4 -For example, the lowest common ancestor (LCA) of nodes 5 and 1 is 3. Another example is LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition. -``` +

```java public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { diff --git a/pics/2e6c72f5-3b8e-4e32-b87b-9491322628fe.png b/pics/2e6c72f5-3b8e-4e32-b87b-9491322628fe.png new file mode 100644 index 00000000..701e37f2 Binary files /dev/null and b/pics/2e6c72f5-3b8e-4e32-b87b-9491322628fe.png differ diff --git a/pics/3179fd1d-617c-476c-8bb2-6270c0715e3d.png b/pics/3179fd1d-617c-476c-8bb2-6270c0715e3d.png new file mode 100644 index 00000000..c51e5b82 Binary files /dev/null and b/pics/3179fd1d-617c-476c-8bb2-6270c0715e3d.png differ diff --git a/pics/323ffd6c-8b54-4f3e-b361-555a6c8bf218.png b/pics/323ffd6c-8b54-4f3e-b361-555a6c8bf218.png new file mode 100644 index 00000000..3316254e Binary files /dev/null and b/pics/323ffd6c-8b54-4f3e-b361-555a6c8bf218.png differ diff --git a/pics/43f2cafa-3568-4a89-a895-4725666b94a6.png b/pics/43f2cafa-3568-4a89-a895-4725666b94a6.png new file mode 100644 index 00000000..010278a2 Binary files /dev/null and b/pics/43f2cafa-3568-4a89-a895-4725666b94a6.png differ diff --git a/pics/5d21b6dc-4b53-47ad-889b-906fcde3e5d4.png b/pics/5d21b6dc-4b53-47ad-889b-906fcde3e5d4.png new file mode 100644 index 00000000..442cd2ae Binary files /dev/null and b/pics/5d21b6dc-4b53-47ad-889b-906fcde3e5d4.png differ diff --git a/pics/755949fa-447f-4bcb-9b97-02df0cfc6838.png b/pics/755949fa-447f-4bcb-9b97-02df0cfc6838.png new file mode 100644 index 00000000..66c38f63 Binary files /dev/null and b/pics/755949fa-447f-4bcb-9b97-02df0cfc6838.png differ diff --git a/pics/8f3b9519-d705-48fe-87ad-2e4052fc81d2.png b/pics/8f3b9519-d705-48fe-87ad-2e4052fc81d2.png new file mode 100644 index 00000000..a8e36ee0 Binary files /dev/null and b/pics/8f3b9519-d705-48fe-87ad-2e4052fc81d2.png differ diff --git a/pics/8f6f9dc9-9ecd-47c8-b50e-2814f0219056.png b/pics/8f6f9dc9-9ecd-47c8-b50e-2814f0219056.png new file mode 100644 index 00000000..21b8a930 Binary files /dev/null and b/pics/8f6f9dc9-9ecd-47c8-b50e-2814f0219056.png differ diff --git a/pics/9405e9a3-1655-4534-a578-56cb4d7be943.png b/pics/9405e9a3-1655-4534-a578-56cb4d7be943.png new file mode 100644 index 00000000..5fac67e3 Binary files /dev/null and b/pics/9405e9a3-1655-4534-a578-56cb4d7be943.png differ diff --git a/pics/a01d1516-8168-461a-a24b-620b9cfc40f4.png b/pics/a01d1516-8168-461a-a24b-620b9cfc40f4.png new file mode 100644 index 00000000..4b9b4b48 Binary files /dev/null and b/pics/a01d1516-8168-461a-a24b-620b9cfc40f4.png differ