今際の国の呵呵君
Wednesday, October 11, 2017
[LeetCode]Populating Next Right Pointers in Each Node II
和I不一样,这道题不限定是perfect binary tree了,所以我们不能用递归。那么我们就得转而用层序遍历的方法,我们把当前层的子节点连起来,然后去下一层,以此类推。时间复杂度O(n),常数空间,代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment