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

@@ -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()