摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal tom+n) to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.思路:将两个给定排序好的数组A和B,将B合并到A中去,意思应该就是不能借用中间 阅读全文
posted @ 2014-03-14 23:29 Awy 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 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.思路:首先我们先熟悉平衡二叉树的定义,平衡二叉树或为空树,或为如下性质的二叉排序树:(1)左右子树深度之差的绝对值不超过1;(2)左右子树仍然为平衡二叉树.平衡因子BF=左子树深 阅读全文
posted @ 2014-03-14 22:11 Awy 阅读(134) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:此题意思就是给你一组排序好的数组转化为平衡二叉树,既然都是排列好的数组了,我们取中间的元素作为根结点,去中间元素的左边区域的中间元素作为左子结点,去中间元素的右边区域的中间元素作为右子结点。以此类推,使用递归,解之!!!/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left... 阅读全文
posted @ 2014-03-14 08:22 Awy 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A =[1,1,2],Your function should return length =2, and A is 阅读全文
posted @ 2014-03-14 00:10 Awy 阅读(289) 评论(0) 推荐(0) 编辑