Count Nodes in a Binary Tree - aloalgo

Count Nodes in a Binary Tree

Easy

You are given the root of a binary tree, return the total number of nodes in the tree.

Example 1

Input
124536
Output
6
Explanation:

The tree has 6 nodes: 1, 2, 3, 4, 5, 6.

Example 2

Input
1
Output
1
Explanation:

The tree consists of a single root node.

Example 3

Input
None
Output
0
Explanation:

An empty tree has no nodes.

Loading...
Input
124536
Output
6

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!