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);
}原文:http://7371901.blog.51cto.com/7361901/1583043