摘要: Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?confused what"{1,#,2,3}"means?> read more on how binary tree is serialized on OJ./** * 阅读全文
posted @ 2014-02-17 18:55 Averill Zheng 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No... 阅读全文
posted @ 2014-02-17 18:31 Averill Zheng 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Note:Recursive solution is trivial, could you do it iteratively?/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode ... 阅读全文
posted @ 2014-02-17 18:10 Averill Zheng 阅读(140) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it to{1,4,2,3}./** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListN... 阅读全文
posted @ 2014-02-17 17:32 Averill Zheng 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode insertionSortList(ListNode head) {... 阅读全文
posted @ 2014-02-17 15:22 Averill Zheng 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list inO(nlogn) time using constant space complexity.Method 1: This code can be accepted by leetcode online judge. The code is the implementation of the meger sort idea./** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x)... 阅读全文
posted @ 2014-02-17 11:41 Averill Zheng 阅读(180) 评论(0) 推荐(0) 编辑