java.lang.Object
g0801_0900.s0863_all_nodes_distance_k_in_binary_tree.Solution

public class Solution extends Object
863 - All Nodes Distance K in Binary Tree.<p>Medium</p> <p>Given the <code>root</code> of a binary tree, the value of a target node <code>target</code>, and an integer <code>k</code>, return <em>an array of the values of all nodes that have a distance</em> <code>k</code> <em>from the target node.</em></p> <p>You can return the answer in <strong>any order</strong>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/06/28/sketch0.png" alt="" /></p> <p><strong>Input:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2</p> <p><strong>Output:</strong> [7,4,1]</p> <p><strong>Explanation:</strong> The nodes that are a distance 2 from the target node (with value 5) have values 7, 4, and 1.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> root = [1], target = 1, k = 3</p> <p><strong>Output:</strong> []</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the tree is in the range <code>[1, 500]</code>.</li> <li><code>0 <= Node.val <= 500</code></li> <li>All the values <code>Node.val</code> are <strong>unique</strong>.</li> <li><code>target</code> is the value of one of the nodes in the tree.</li> <li><code>0 <= k <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details