← 返回 meta 的题目列表All Nodes Distance K in Binary Tree
类型:online_judge
Given a binary tree (each node has a unique value), a target node, and an integer K, return a list of the values of all nodes that have a distance K from the target node target.
Note: The list returned can be in any order.
Example
Input:
root = [3,5,1,6,2,0,8,null,null,7,4]
target = 5
K = 2
Output: [7,4,1]
Constraints
The tree is non-empty.
The distance K from the target is defined as the number of different nodes from target to the node.
The number of nodes in the tree is less than 500.
Every node has a unique value.
Example
Input
[3,5,1,6,2,0,8,null,null,7,4]
5
2