简历:The Google Resume: How to Prepare for a Career and Land a Job at Apple, Microsoft, Google, or any Top Tech Company
算法学习书籍:Introduction to Algorithms
编程珠玑:Programming Pearls (2nd Edition)
C++ 学习:The C++ Programming Language, 4th Edition
经典操作系统书籍,龙书:Operating System Concepts
创业:The Start-up of You: Adapt to the Future, Invest in Yourself, and Transform Your Career
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
1 / \ 2 2 / \ / \ 3 4 4 3
But the following is not:
1 / \ 2 2 \ \ 3 3
Note:
Bonus points if you could solve it both recursively and iteratively.
Bonus points if you could solve it both recursively and iteratively.
这题递归法比较简单,几行代码的事情。但是我在oj的时候老是不通过,逻辑很简单,而且我确定是对的,后来自己跑到emacs上面调试,发现有segmentation fault,原来是我做判断的时候的一句话
if(l->val==r->val&&!l&&!r)
这种情况下,l or r 有可能是null,那么就没有l->val or r->val, 就会出现问题,这样把空判断提前就可以了,细节,但一定要注意!
这题难的是iterative的解法,基本做法是BFS,一层一层看是否对称,然后用两个queue来存储结点。
No comments:
Post a Comment