//求节点个数
public static int treeSize = 0;
public static void size (Node root) {
if(root == null) {
return;
}
treeSize++;
size(root.left);
size(root.right);
}
public static int size(Node root) {
if(root == null) {
return 0;
}
//这棵树的节点个数:1+左子树节点个数+右子树节点个数,递归
return 1 + size(root.left) + size(root.right);
}
求二叉树节点个数
最新推荐文章于 2023-09-17 19:26:39 发布