Tap here to switch tabs
Problem
Submissions

Problem: Find All The Lonely Nodes

Try to solve the Find All The Lonely Nodes problem.

Statement

In a binary tree, a lonely node is defined as a node that is the only child of its parent. The root node is never lonely because it does not have a parent.

Given the root of a binary tree, return an array containing the values of all lonely nodes in the tree. The values may be returned in any order.

Constraints:

  • The number of nodes in the tree is in the range [1,1000][1, 1000].

  • 1≤1 \leq Node.val ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find All The Lonely Nodes

Try to solve the Find All The Lonely Nodes problem.

Statement

In a binary tree, a lonely node is defined as a node that is the only child of its parent. The root node is never lonely because it does not have a parent.

Given the root of a binary tree, return an array containing the values of all lonely nodes in the tree. The values may be returned in any order.

Constraints:

  • The number of nodes in the tree is in the range [1,1000][1, 1000].

  • 1≤1 \leq Node.val ≤106\leq 10^6