Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e527e8e

Browse files
Update 863-All-Nodes-Distance-K-in-Binary-Tree.java
1 parent dc4ab5d commit e527e8e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

java/863-All-Nodes-Distance-K-in-Binary-Tree.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//Just store the value for parent values in a map and just do bfs as we do in graph.
1+
//Just store the value for parent values of the nodes in a map and just do bfs as we do in graph.
22

33
class Solution {
44
public List<Integer> distanceK(TreeNode root, TreeNode target, int k) {
@@ -20,6 +20,8 @@ public List<Integer> distanceK(TreeNode root, TreeNode target, int k) {
2020
}
2121
}
2222
}
23+
//Now do the bfs
24+
//Same as we do in graphs with a visited set
2325
Queue<TreeNode> q2 = new LinkedList<>();
2426
HashSet<TreeNode> vis = new HashSet<>();
2527
List<Integer> ans = new ArrayList<>();

0 commit comments

Comments
 (0)