January 16, 2016
First time after 9 years, I installed Eclipse, J2SE, and then, set up Java developer IDE Eclipse, ran the first Java program. Such a great ride to enjoy Java programming. Still remember that in 2006 - 2007, spent over 10 hours daily to read/ run/ maintain software using Java programming language, when I worked for a small startup called Siva Corp Inc. in the city of Delray Beach, Florida, USA.
Just bring all my good memory back about programming using Java.
http://buttercola.blogspot.ca/2014/09/leetcode-n-queens.html
Leetcode 314:
https://github.com/jianminchen/Leetcode_C-/blob/master/BinaryTreeVerticalOrderTraversal_314.java
Another blog using C++,
http://buttercola.blogspot.ca/2014/12/facebook-print-binary-tree-in-vertical.html
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
Showing posts with label Level Order Traversal. Show all posts
Showing posts with label Level Order Traversal. Show all posts
Saturday, January 16, 2016
Thursday, July 23, 2015
Leetcode 102: Binary tree level order traversal
July 23, 2015
Problem statement:
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
For example:
Given binary tree
Given binary tree
{3,9,20,#,#,15,7}, 3
/ \
9 20
/ \
15 7
return its level order traversal as:
[ [3], [9,20], [15,7] ]
confused what
"{1,#,2,3}" means? > read more on how binary tree is serialized on OJ.
写代码发现很多问题. 程序要多写, 多练. 背算法可能也是一个途径. 从C++代码, 转化成C#, 犯了几个错. 一下学习到很多C#知识, 感觉不错! 练习6种方法.
1. Solution 1: (push extra null node in the queue to divide level)
Read the blog:
convert it to C# code:
C# code passing leetcode online judge:
Solution 2: (using 3 variables to help queue to do BFS algorithm)
blog:
C# code:
Solution 3: DFS algorithm:
blog:
C# code:
Solution 4: using two containers for current level, next level
blog:
C# code:
https://github.com/jianminchen/BTreeLevelOrderTraversal/blob/master/BTreeLevelOrderTraversal5.cs
Solution 5: one queue and iteratively solution (单个queue的迭代解法)
blog:
blog:
C# code:
https://github.com/jianminchen/BTreeLevelOrderTraversal/blob/master/BTreeLevelOrderTraversal6.cs
Solution 6: one queue and extra node null into queue to mark end of level
blog:
C# code:
https://github.com/jianminchen/BTreeLevelOrderTraversal/blob/master/BTreeLevelOrderTraversal7.cs
Blogs to read:
2. http://siddontang.gitbooks.io/leetcode-solution/content/tree/binary_tree_level_order_traversal.html
Tuesday, June 9, 2015
Leetcode: zigzag order traversal of binary tree
One more C# practice on level order traversal. So excited to read my past practice in 2015, April 29. Cheers!
April 29, 2015
One thing I do not like is to use two while loop, and since it makes me wonder how to make it more simple and readable.
This is a better solution, I like it more:
Here is C# code I write and test on April 29, 2015:
Follow up
May 3, 2018
I spent over 30 minutes to review the C# code writting in 2015. I am not happy about the coding style, and also the code is not easy to read. I need to debug the code, and then update readable variable names, and understand how to apply stack to store nodes for each level.
Here is the C# code I ran and passed all test cases.
Subscribe to:
Posts (Atom)