- 递归
class Solution {
public int countNodes(TreeNode root) {
if(root == null) return 0;
return countNodes(root.left)+countNodes(root.right)+1;
}
}
标签:leetcode222,个数,二叉树,countNodes,root,节点
From: https://www.cnblogs.com/xzh-yyds/p/16625529.html