Skip to content

Commit cb6e247

Browse files
committed
update
1 parent 301b841 commit cb6e247

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

leetcode/solution/src/ConstructStringFromBinaryTree.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
/**
22
* https://leetcode.com/articles/construct-string-from-binary-tree/
33
*/
4+
5+
/**
6+
* 这题不难,主要是搞清楚题目意思
7+
* 即返回root + (左子树) + (右子树)
8+
* 不过要注意几个特殊情况,如果左右子树都为null,则只返回root
9+
* 如果左子树为null,右子树非null,则返回root + () + (右子树)
10+
* 如果左子树非null,右子树为null,则返回root + (左子树)
11+
*/
412
public class ConstructStringFromBinaryTree {
513

614
/**

leetcode/src/Main.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,12 @@ public class Main {
66

77
public static class Solution {
88

9-
public int kthSmallest(TreeNode root, int k) {
10-
Stack<TreeNode> stack = new Stack<>();
11-
while (!stack.isEmpty() || root != null) {
12-
if (root != null) {
13-
stack.push(root);
14-
root = root.left;
15-
} else {
16-
root = stack.pop();
179

18-
if (--k == 0) {
19-
return root.val;
20-
}
2110

22-
root = root.right;
23-
}
24-
}
25-
return -1;
26-
}
2711
}
2812

2913
public static void main(String[] args) {
3014
Solution s = new Solution();
31-
TreeNode root1 = new TreeNode(1);
32-
System.out.println(f);
15+
System.out.println(a);
3316
}
3417
}

0 commit comments

Comments
 (0)