获取无限子集
1.树形
2.返回一个list
递归方法:
public static List<TreeNode> buildList(Long parentId, List<TreeNode> nodes) {
List<TreeNode> list = new ArrayList<>();
for (TreeNode node : nodes) {
if (Objects.equals(parentId, node.getParentId())) {
list.add(node);
list.addAll(buildList(node.getId(), nodes));
}
}
return list;
}