Saturday, August 22, 2015

Leetcode questions 100 - 110

August 22, 2015

100 Same Tree

101 Symmetric Tree

102 Binary Tree Level Order Traversal

103 Binary Tree Zigzag Level Order Traversal

104 Maximum Depth of Binary Tree

105 Construct Binary Tree from Preorder and Inorder Traversal

106 Constructu Binary Tree from Inorder and Postorder Traversal

107 Binary Tree level Order Traversal II

108 Convert Sorted Array To Binary Search Tree

109 Convert Sorted List to Binary Search Tree

110 Balanced Binary Tree

--


101 Symmetric Tree (Sept. 8, 2015)

102 Binary Tree Level Order Traversal
6 different solutions:


103 Binary Tree Zigzag Level Order Traversal

104 Maximum Depth of Binary Tree
108  Convert sorted array to binary search tree (No. 108)


109 Convert sorted list to binary search tree (No. 109)

8/25/2015
Read the following blogs:

C#, bottom up, time O(n), space O(log n) solution - best solution:
C#, top down, time O(n^2), space O(long n) solution - naive solution:

worked on code 2 times, first time, the calculation is kind of messy, then, worked on Leetcode question 108, get the idea to make it more simple; tips like len/2 only shows once, afterwards, use m instead. Just need to improve coding, think to make it more abstract, simple.

https://github.com/jianminchen/Leetcode_C-/blob/master/109ConvertSortedListToBinarySearchTreeC.cs

9/21/2015
Review the best solution, and then, totally forgot the bottom up solution idea. So, update the code with more comment.

Need to review more about bottom up/ top down solution in tree problems. Get more experience on bottom-up solution, read some articles about it. 

No comments:

Post a Comment