算法篇-递归算法(一)
愿历尽千帆,归来仍是少年
相似文章:https://blog.csdn.net/xzx19930928/article/details/106800519
需求描述(获取到所有子级放到集合中遍历)
代码展示:
1 public static List<CommonTree> buildTreeToList(Integer staffId, List<CommonTree> commonTreeList, boolean isRe) { 2 List<CommonTree> list = new ArrayList<>(); 3 commonTreeList.forEach(o -> { 4 if ((!Objects.isNull(o.getOwnerStaffId()) && staffId.intValue() == o.getOwnerStaffId()) || isRe) { 5 list.add(o); 6 list.addAll(buildTreeToList(staffId, o.getChildren(), true)); 7 } else { 8 list.addAll(buildTreeToList(staffId, o.getChildren(), false)); 9 } 10 }); 11 return list; 12 }