[Algorithm] Level Order Binary Tree Traversal (Iterative and Recursive)

Traverse a binary tree in level order is intuitive. We can initialize a queue and add elements. Every cycle you need to print out the nodes in the queue, and add their children to queue, until queue is empty. However, since the recursive solution for pre-order, in-order, and post-order traverse is quite easy, I wonder … Read more [Algorithm] Level Order Binary Tree Traversal (Iterative and Recursive)

[LeetCode] Longest Valid Parentheses

Got stuck in this problem for one hour. I was trying to use a variable left to count the left parentheses. However, we should not only count the number of them, but also the position of them. Then we need to use stack. There is a very elegant solution here (In Java): http://rleetcode.blogspot.com/2014/01/longest-valid-parentheses.html This problem really cost … Read more [LeetCode] Longest Valid Parentheses