lcs 08/13

99. Recover Binary Search Tree travese in order. The result should be sorted ascending. The misplaced larger element will be close to head, while the smaller one will be close to end. For example, 1 2 3 is the in order. But the wrong seq is like 3 2 1. Apparently, 3 > 2 so 3 is the first node. 2 > 1, so 1 is the second one.

lcs 08/12

297. Serialize and Deserialize Binary Tree deque inherits from linkedlist(collection). represent separator and null as a String. string and char are not same. append complete subtree ex “1,null,null,” 105. Construct Binary Tree from Preorder and Inorder Traversal recursive solution is straightforward. The only thing is that jump idx to find right start in inorder array. To speed up, we can cache inorder and index in the front.

leetcode 102

4. Median of Two Sorted Arrays Pure math. Median definition is the median is used for dividing a set into two equal length subsets, that one subset is always greater than the other. 102. Binary Tree Level Order Traversal The best way to to iterate tree level by level is to use for loop in Java. (BFS) return null is not same as return; (empty) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 public class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res = new LinkedList<List<Integer>>(); Queue<TreeNode> q = new LinkedList<TreeNode>(); if (root == null) return res; q.

175. Combine Two Tables

175. Combine Two Tables Solution select FirstName, LastName, City, State from person left join address on person.personid = address.personid; Summary

176. Second Highest Salary

176. Second Highest Salary Solution select (select salary from employee group by salary order by salary desc limit 1 offset 1) as SecondHighestSalary; Summary There is a trick to print null when result is empty.