java 计算树结构叶子节点总数

public int sumtotal(List<CommonTree> listCommon,int sum) {
        for(CommonTree commonTree:listCommon) {
            List<CommonTree> chList=commonTree.getChildren();
            if(chList!=null&&chList.size()>0) {
                sum=sumtotal(chList,sum);
            }else {
                sum+=1;
            }
        }
        return sum;
    }

    原文作者:JoeyGiro、
    原文地址: https://blog.csdn.net/qq_33398459/article/details/107952585
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞