Skip to content

Commit d6f8678

Browse files
refactor 742
1 parent 25fc629 commit d6f8678

File tree

1 file changed

+0
-47
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+0
-47
lines changed

src/main/java/com/fishercoder/solutions/_742.java

-47
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,6 @@
99
import java.util.Queue;
1010
import java.util.Set;
1111

12-
/**
13-
* 742. Closest Leaf in a Binary Tree
14-
*
15-
* Given a binary tree where every node has a unique value, and a target key k, find the value of the nearest leaf node to target k in the tree.
16-
* Here, nearest to a leaf means the least number of edges travelled on the binary tree to reach any leaf of the tree. Also, a node is called a leaf if it has no children.
17-
* In the following examples, the input tree is represented in flattened form row by row. The actual root tree given will be a TreeNode object.
18-
*
19-
* Example 1:
20-
* Input:
21-
* root = [1, 3, 2], k = 1
22-
*
23-
* Diagram of binary tree:
24-
* 1
25-
* / \
26-
* 3 2
27-
*
28-
* Output: 2 (or 3)
29-
* Explanation: Either 2 or 3 is the nearest leaf node to the target of 1.
30-
*
31-
* Example 2:
32-
* Input:
33-
* root = [1], k = 1
34-
* Output: 1
35-
* Explanation: The nearest leaf node is the root node itself.
36-
*
37-
* Example 3:
38-
* Input:
39-
* root = [1,2,3,4,null,null,null,5,null,6], k = 2
40-
*
41-
* Diagram of binary tree:
42-
* 1
43-
* / \
44-
* 2 3
45-
* /
46-
* 4
47-
* /
48-
* 5
49-
* /
50-
* 6
51-
*
52-
* Output: 3
53-
* Explanation: The leaf node with value 3 (and not the leaf node with value 6) is nearest to the node with value 2.
54-
* Note:
55-
* root represents a binary tree with at least 1 node and at most 1000 nodes.
56-
* Every node has a unique node.val in range [1, 1000].
57-
* There exists some node in the given binary tree for which node.val == k.
58-
* */
5912
public class _742 {
6013
public static class Solution1 {
6114
public int findClosestLeaf(TreeNode root, int k) {

0 commit comments

Comments
 (0)