完全二叉树的节点个数
以上是正常版的完全二叉树的节点个数
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public int countNodes(TreeNode root) {
}
}
如果题目是将TreeNode改成TreeNode数组,并且没有左右节点。
数组的每一个元素都是一个单独的节点。
如何求完全二叉树的节点个数,希望大佬解答。
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left=null;
* TreeNode right=null;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
*
* }
*/
class Solution {
public int countNodes(TreeNode[] root) {
}
}