Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c8ef0d

Browse files
Update 863-All-Nodes-Distance-K-in-Binary-Tree.java
1 parent3cd4073 commit2c8ef0d

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 valuesof the nodesin a map and just do bfs as we do in graph.
22

33
classSolution {
44
publicList<Integer>distanceK(TreeNoderoot,TreeNodetarget,intk) {
@@ -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 =newLinkedList<>();
2426
HashSet<TreeNode>vis =newHashSet<>();
2527
List<Integer>ans =newArrayList<>();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp