LeetCode-222 Posted on 2020-11-24 Edited on 2025-02-13 In LeetCode 题目 结果 代码普世众生的解法12345678class Solution { public int countNodes(TreeNode root) { if (root == null) { return 0; } return 1 + countNodes(root.left) + countNodes(root.right); }} 复杂度时间复杂度:O(n),n为节点个数 空间复杂度:O(log n)