AlgoFrames

Complete the node counter

Warm-up · Fill in the code · about 4 min

Fill the two blanks so countNodes returns the number of nodes in a binary tree.

Example 1

Input:

[[1,2,3,4,5,null,6]]

Output:

6

Constraints

  • 0 ≤ number of nodes ≤ 1,000
  • -1,000 ≤ Node.val ≤ 1,000
  • The tree is given in level order; null marks a missing child

Learn the idea first: Recursive problems on trees: height, size, mirror, paths, a visual lesson.

More Recursive problems on trees: height, size, mirror, paths problems