
tree traversal
文章平均质量分 78
smallfish_yy
人最幸福的事之一就是把爱好变成自己的工作。
展开
-
Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Analysis: 1. Get the middle element of the current array and construct the root with such value.原创 2013-12-25 09:00:02 · 384 阅读 · 0 评论 -
Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut原创 2014-01-18 05:20:30 · 427 阅读 · 0 评论 -
Binary Tree Level Order Traversal
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 {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2013-12-28 06:31:38 · 398 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2014-01-18 04:14:18 · 369 阅读 · 0 评论 -
Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2014-02-05 02:59:44 · 383 阅读 · 0 评论 -
Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary原创 2014-02-09 09:32:49 · 372 阅读 · 0 评论 -
Morris Traversal
http://blog.youkuaiyun.com/ithomer/article/category/694817转载 2014-02-22 09:14:31 · 442 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Analysis: /** * Definition for singly-linked list. * public class ListNode { *原创 2014-02-12 09:09:42 · 409 阅读 · 0 评论