Skip to content

Commit

Permalink
Section7-9. Tree 말단노드까지의 가장 짧은 경로(DFS)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuseon25 committed Jan 30, 2025
1 parent 19aaf30 commit c0524cf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Section07/말단노드_최단거리_DFS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package 인프런.Section07;

public class 말단노드_최단거리_DFS {
Node root;

public int DFS(int L, Node root) {
if(root.lt == null && root.rt == null) return L;
else return Math.min(DFS(L+1, root.lt), DFS(L+1, root.rt));
}

public static void main(String[] args) {
말단노드_최단거리_DFS tree = new 말단노드_최단거리_DFS();

tree.root = new Node(1);
tree.root.lt = new Node(2);
tree.root.rt = new Node(3);
tree.root.lt.lt = new Node(4);
tree.root.lt.rt = new Node(5);

System.out.print(tree.DFS(0, tree.root));
}
}

0 comments on commit c0524cf

Please sign in to comment.