import java.util.*;
/*
* public class TreeNode {
* int val = 0;
* TreeNode left = null;
* TreeNode right = null;
* public TreeNode(int val) {
* this.val = val;
* }
* }
*/
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head TreeNode类
* @return int整型
*/
public int nodeNum (TreeNode head) {
// write code here
if (head == null) {
return 0;
}
// 左边节点个数
int left = nodeNum(head.left);
// 右边节点个数
int right = nodeNum(head.right);
return left + right + 1;
}
}



京公网安备 11010502036488号