1469. Find All The Lonely Nodes

https://leetcode.com/problems/find-all-the-lonely-nodes

Description

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

Given the root of a binary tree, return an array containing the values of all lonely nodes in the tree. Return the list in any order.

Example 1:

Example 2:

Example 3:

Example 4:

Example 5:

Constraints:

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

  • Each node's value is between [1, 10^6].

ac

Last updated

Was this helpful?