Solo Supervisors
Easy · tree dfs
A small company draws its org chart as a binary tree: every employee has at most two direct reports, a left one and a right one. The chart is given by its root, the head of the company.
A solo supervisor is an employee who has exactly one direct report: not none, and not two.
Return how many solo supervisors the chart contains. An empty chart contains none.
Examples
Example 1
Input: root = [8, 3, 5, 1, null, 2, 9]
Output: 1
Employee 3 has a single report (1). Employee 5 has two, and 8, 1, 2 and 9 have two or none.
Example 2
Input: root = [1, null, 2, null, 3]
Output: 2
Employee 1 supervises only 2, and employee 2 supervises only 3. Employee 3 has nobody.
Example 3
Input: root = []
Output: 0
Constraints
- The number of employees is in the range [0, 1000].
- -1000 <= Node.val <= 1000