List<List<Node>> build(Node root) { List<List<Node>> toReturn = initList(); build(root, 0, toReturn); return toReturn; } private void build(Node node, int dep, List<List<Node>> lists) { if (node == null) return; List<Node> list = lists.get(dep); if (list == null) list = initList(); list.add(node); build(node.left, dep + 1, lists); build(node.right, dep + 1, lists); }
时间: 2024-10-25 00:51:28