auto commit
This commit is contained in:
@ -254,16 +254,16 @@ public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
|||||||
public TreeNode reConstructBinaryTree(int[] pre, int[] in) {
|
public TreeNode reConstructBinaryTree(int[] pre, int[] in) {
|
||||||
return reConstructBinaryTree(pre, 0, pre.length - 1, in, 0, in.length - 1);
|
return reConstructBinaryTree(pre, 0, pre.length - 1, in, 0, in.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TreeNode reConstructBinaryTree(int[] pre, int preL, int preR, int[] in, int inL, int inR) {
|
private TreeNode reConstructBinaryTree(int[] pre, int preL, int preR, int[] in, int inL, int inR) {
|
||||||
if(preL > preR || inL > inR) return null;
|
if (preL == preR) return new TreeNode(pre[preL]);
|
||||||
|
if (preL > preR || inL > inR) return null;
|
||||||
TreeNode root = new TreeNode(pre[preL]);
|
TreeNode root = new TreeNode(pre[preL]);
|
||||||
if (preL != preR) {
|
int midIdx = inL;
|
||||||
int idx = inL;
|
while (midIdx <= inR && in[midIdx] != root.val) midIdx++;
|
||||||
while (idx <= inR && in[idx] != root.val) idx++;
|
int leftTreeSize = midIdx - inL;
|
||||||
int leftTreeLen = idx - inL;
|
root.left = reConstructBinaryTree(pre, preL + 1, preL + leftTreeSize, in, inL, inL + leftTreeSize - 1);
|
||||||
root.left = reConstructBinaryTree(pre, preL + 1, preL + leftTreeLen, in, inL, inL + leftTreeLen - 1);
|
root.right = reConstructBinaryTree(pre, preL + leftTreeSize + 1, preR, in, inL + leftTreeSize + 1, inR);
|
||||||
root.right = reConstructBinaryTree(pre, preL + leftTreeLen + 1, preR, in, inL + leftTreeLen + 1, inR);
|
|
||||||
}
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -274,6 +274,13 @@ private TreeNode reConstructBinaryTree(int[] pre, int preL, int preR, int[] in,
|
|||||||
|
|
||||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><E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D>㲻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD>㣬ͬʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>롣
|
||||||
|
|
||||||
|
**<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˼·**
|
||||||
|
|
||||||
|
- <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><D5A3><EFBFBD>ô<EFBFBD>ýڵ<C3BD><DAB5><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ㣻
|
||||||
|
- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ýڵ<C3BD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƚڵ㡣
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
```java
|
```java
|
||||||
public TreeLinkNode GetNext(TreeLinkNode pNode) {
|
public TreeLinkNode GetNext(TreeLinkNode pNode) {
|
||||||
if (pNode == null) return null;
|
if (pNode == null) return null;
|
||||||
|
BIN
pics/6fec7f56-a685-4232-b03e-c92a8dfba486.png
Normal file
BIN
pics/6fec7f56-a685-4232-b03e-c92a8dfba486.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
Reference in New Issue
Block a user