本文共 434 字,大约阅读时间需要 1 分钟。
private int getNumberOfLeaves(TreeNoderoot){ if(root.left == null && root.right == null){ return 1; }else if(root.left == null){ return getNumberOfLeaves(root.right); }else if(root.right == null){ return getNumberOfLeaves(root.left); }else{ return getNumberOfLeaves(root.left) + getNumberOfLeaves(root.right); } }
转载地址:http://zpzai.baihongyu.com/