Given the root of a binary tree, return the total number of nodes that have exactly one child (either a left child or a right child, but not both).
Explanation: Node 2 has only one child (4). Node 1 has two children (2, 3). Nodes 3 and 4 have zero children. Thus, there is only 1 node with exactly one child.
Explanation: Node 1 has only one child (2). Node 2 has only one child (3). Node 3 has zero children. Thus, there are 2 nodes with exactly one child.
Master coding challenges related to Trees and solve the Count Single-Child Nodes problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak