所用语言 Java 所用知识 二叉树 解题思路 定义全局变量计数,递归即可 完整代码 int count =0; public int countNodes (TreeNode root) { // write code here dfs(root); return count; } public void dfs(TreeNode root){ if(root==null)return; count++; dfs(root.left); dfs(root.right); }