Fix the util of array to tree.

This commit is contained in:
Yudong Jin 2022-12-02 00:53:19 +08:00
parent e20bc251f5
commit d85a14521f
3 changed files with 5 additions and 2 deletions

View file

@ -29,7 +29,7 @@
## 关于本书
本书致力于达成以下目标:
本书面向数据结构与算法初学者,致力于达成以下目标:
- 开源免费,所有同学都可在网上获取本书;
- 新手友好,适合算法初学者自主学习入门;

View file

@ -26,6 +26,9 @@ public class TreeNode {
* @return
*/
public static TreeNode arrToTree(Integer[] arr) {
if (arr.length == 0)
return null;
TreeNode root = new TreeNode(arr[0]);
Queue<TreeNode> queue = new LinkedList<>() {{ add(root); }};
int i = 1;

View file

@ -24,7 +24,7 @@ def list_to_tree(arr):
[type]: [description]
"""
if not arr:
return
return None
i = 1
root = TreeNode(int(arr[0]))
queue = collections.deque()