All Nodes Distance K In Binary Tree, is a LeetCode problem. In this post we will see how we can solve this challenge in C++

Problem Description

Example 1 :

Input: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, K = 2

Output: [7,4,1]

Explanation: The nodes that are a distance 2 from the target node (with value 5) have values 7, 4, and 1.

Note :

The given tree is non-empty.

0 <= K <= 1000 .

0 <= K <= 1000.

func distanceK(root *TreeNode, target *TreeNode, K int) []int { visit := []int{} ....

You can find the full details of the problem All Nodes Distance K in Binary Tree at LeetCode

Solution: Please check the main.cpp snippet for the solution.

This solution originally posted at: Github by @kamyu104