Skip to content

Commit ff6164d

Browse files
author
Botao Xiao
committed
[Function add]
1. Add leetcode solutions.
1 parent d126188 commit ff6164d

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@
309309

310310
[172. Factorial Trailing Zeroes](https://github.com/Seanforfun/Algorithm-and-Leetcode/blob/master/leetcode/172.%20Factorial%20Trailing%20Zeroes.md)
311311

312+
[173. Binary Search Tree Iterator](https://github.com/Seanforfun/Algorithm-and-Leetcode/blob/master/leetcode/173.%20Binary%20Search%20Tree%20Iterator.md)
313+
314+
[175. Combine Two Tables](https://github.com/Seanforfun/Algorithm-and-Leetcode/blob/master/leetcode/175.%20Combine%20Two%20Tables.md)
315+
312316
## Algorithm(4th_Edition)
313317
Reading notes of book Algorithm(4th Algorithm),ISBN: 9787115293800.
314318
All java realization codes are placed in different packages.

leetcode/173. Binary Search Tree Iterator.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,44 @@ public class BSTIterator {
102102
* BSTIterator i = new BSTIterator(root);
103103
* while (i.hasNext()) v[f()] = i.next();
104104
*/
105-
```
105+
```
106+
107+
### 二刷
108+
```Java
109+
/**
110+
* Definition for binary tree
111+
* public class TreeNode {
112+
* int val;
113+
* TreeNode left;
114+
* TreeNode right;
115+
* TreeNode(int x) { val = x; }
116+
* }
117+
*/
118+
public class BSTIterator {
119+
private List<Integer> inorder = new LinkedList<>();
120+
private ListIterator<Integer> cur = null;
121+
public BSTIterator(TreeNode root) {
122+
inorder(root, inorder);
123+
cur = inorder.listIterator(0);
124+
}
125+
private void inorder(TreeNode root, List<Integer> list){
126+
if(root == null) return;
127+
inorder(root.left, list);
128+
list.add(root.val);
129+
inorder(root.right, list);
130+
}
131+
/** @return whether we have a next smallest number */
132+
public boolean hasNext() {
133+
return cur.hasNext();
134+
}
135+
/** @return the next smallest number */
136+
public int next() {
137+
return cur.next();
138+
}
139+
}
140+
/**
141+
* Your BSTIterator will be called like this:
142+
* BSTIterator i = new BSTIterator(root);
143+
* while (i.hasNext()) v[f()] = i.next();
144+
*/
145+
```

leetcode/175. Combine Two Tables.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,17 @@ left join
4242
Address
4343
on
4444
Person.PersonId = Address.PersonId; //以id作为连接点。
45-
```
45+
```
46+
47+
### 二刷
48+
1. 我们应该使用左外连接。
49+
2. 我们使用Person作为左表,以左表为基准,获得所有的信息。
50+
```Java
51+
# Write your MySQL query statement below
52+
SELECT
53+
p.FirstName, p.LastName, a.City, a.State
54+
FROM Person p
55+
LEFT OUTER JOIN
56+
Address a
57+
ON p.PersonId = a.PersonId;
58+
```

0 commit comments

Comments
 (0)