auto commit

This commit is contained in:
CyC2018 2019-04-23 23:03:14 +08:00
parent 4f6d5b0478
commit 169cbbb5b1
12 changed files with 12 additions and 12 deletions

View File

@ -87,7 +87,7 @@ public boolean IsPopOrder(int[] pushSequence, int[] popSequence) {
例如以下二叉树层次遍历的结果为1,2,3,4,5,6,7
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/348bc2db-582e-4aca-9f88-38c40e9a0e69.png" width="250"/> </div><br>
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/d5e838cf-d8a2-49af-90df-1b2a714ee676.jpg" width="250"/> </div><br>
## 解题思路
@ -195,7 +195,7 @@ public ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
例如,下图是后序遍历序列 1,3,2 所对应的二叉搜索树。
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/836a4eaf-4798-4e48-b52a-a3dab9435ace.png" width="150"/> </div><br>
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/13454fa1-23a8-4578-9663-2b13a6af564a.jpg" width="150"/> </div><br>
## 解题思路
@ -230,7 +230,7 @@ private boolean verify(int[] sequence, int first, int last) {
下图的二叉树有两条和为 22 的路径10, 5, 7 和 10, 12
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/f5477abd-c246-4851-89ab-6b1cde2549b1.png" width="200"/> </div><br>
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/ed77b0e6-38d9-4a34-844f-724f3ffa2c12.jpg" width="200"/> </div><br>
## 解题思路
@ -277,21 +277,21 @@ public class RandomListNode {
}
```
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/a01d1516-8168-461a-a24b-620b9cfc40f4.png" width="300"/> </div><br>
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/66a01953-5303-43b1-8646-0c77b825e980.png" width="300"/> </div><br>
## 解题思路
第一步,在每个节点的后面插入复制的节点。
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/2e6c72f5-3b8e-4e32-b87b-9491322628fe.png" width="600"/> </div><br>
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/dfd5d3f8-673c-486b-8ecf-d2082107b67b.png" width="600"/> </div><br>
第二步,对复制节点的 random 链接进行赋值。
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/323ffd6c-8b54-4f3e-b361-555a6c8bf218.png" width="600"/> </div><br>
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/cafbfeb8-7dfe-4c0a-a3c9-750eeb824068.png" width="600"/> </div><br>
第三步,拆分。
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/8f3b9519-d705-48fe-87ad-2e4052fc81d2.png" width="600"/> </div><br>
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/e151b5df-5390-4365-b66e-b130cd253c12.png" width="600"/> </div><br>
```java
public RandomListNode Clone(RandomListNode pHead) {
@ -333,7 +333,7 @@ public RandomListNode Clone(RandomListNode pHead) {
输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/79b12431-6d9d-4a7d-985b-1b79bc5bf5fb.png" width="400"/> </div><br>
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/05a08f2e-9914-4a77-92ef-aebeaecf4f66.jpg" width="400"/> </div><br>
## 解题思路

View File

@ -285,12 +285,12 @@ public int StrToInt(String str) {
### 二叉查找树
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/b39a085e-e7a2-4657-b75e-ba1652a4b132.jpg" width="300"/> </div><br>
[Leetcode : 235. Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/description/)
二叉查找树中,两个节点 p, q 的公共祖先 root 满足 root.val >= p.val && root.val <= q.val。
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/047faac4-a368-4565-8331-2b66253080d3.jpg" width="250"/> </div><br>
```java
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if (root == null)
@ -305,12 +305,12 @@ public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
### 普通二叉树
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/37a72755-4890-4b42-9eab-b0084e0c54d9.png" width="300"/> </div><br>
[Leetcode : 236. Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/description/)
在左右子树中查找是否存在 p 或者 q如果 p 和 q 分别在两个子树中,那么就说明根节点就是最低公共祖先。
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/d27c99f0-7881-4f2d-9675-c75cbdee3acd.jpg" width="250"/> </div><br>
```java
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if (root == null || root == p || root == q)

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB