摘要:
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ... 阅读全文
posted @ 2013-09-23 03:45
LEDYC
阅读(156)
评论(0)
推荐(1)
摘要:
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeverynode never differ by more than 1.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNo... 阅读全文
posted @ 2013-09-23 03:32
LEDYC
阅读(169)
评论(0)
推荐(1)
摘要:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.---需要总长度,遍历一遍,1. 可以再这个时候吧list转成array, 费地方2. 或者跟array一样每次走半个长度找到mid, O(NlogN), logN层,每层遍历N,费时间/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode n... 阅读全文
posted @ 2013-09-23 02:57
LEDYC
阅读(184)
评论(0)
推荐(1)
摘要:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public TreeNode... 阅读全文
posted @ 2013-09-23 02:53
LEDYC
阅读(121)
评论(0)
推荐(1)
摘要:
Given a binary tree, return thebottom-up level ordertraversal 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}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]conf... 阅读全文
posted @ 2013-09-23 02:42
LEDYC
阅读(139)
评论(0)
推荐(1)
浙公网安备 33010602011771号