Fix the util of array to tree.
This commit is contained in:
parent
e20bc251f5
commit
d85a14521f
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
## 关于本书
|
## 关于本书
|
||||||
|
|
||||||
本书致力于达成以下目标:
|
本书面向数据结构与算法初学者,致力于达成以下目标:
|
||||||
|
|
||||||
- 开源免费,所有同学都可在网上获取本书;
|
- 开源免费,所有同学都可在网上获取本书;
|
||||||
- 新手友好,适合算法初学者自主学习入门;
|
- 新手友好,适合算法初学者自主学习入门;
|
||||||
|
@ -26,6 +26,9 @@ public class TreeNode {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static TreeNode arrToTree(Integer[] arr) {
|
public static TreeNode arrToTree(Integer[] arr) {
|
||||||
|
if (arr.length == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
TreeNode root = new TreeNode(arr[0]);
|
TreeNode root = new TreeNode(arr[0]);
|
||||||
Queue<TreeNode> queue = new LinkedList<>() {{ add(root); }};
|
Queue<TreeNode> queue = new LinkedList<>() {{ add(root); }};
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
@ -24,7 +24,7 @@ def list_to_tree(arr):
|
|||||||
[type]: [description]
|
[type]: [description]
|
||||||
"""
|
"""
|
||||||
if not arr:
|
if not arr:
|
||||||
return
|
return None
|
||||||
i = 1
|
i = 1
|
||||||
root = TreeNode(int(arr[0]))
|
root = TreeNode(int(arr[0]))
|
||||||
queue = collections.deque()
|
queue = collections.deque()
|
||||||
|
Loading…
Reference in New Issue
Block a user