02 2015 档案

摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2015-02-26 20:59 vincently 阅读(132) 评论(0) 推荐(0)
摘要: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 le... 阅读全文
posted @ 2015-02-26 20:54 vincently 阅读(182) 评论(0) 推荐(0)
摘要:1. 简要介绍 关于二叉树问题,由于其本身固有的递归属性,通常我们可以用递归算法来解决。(《编程之美》,P253) 总结的题目主要以leetcode题目、《剑指offer》以及《编程之美》的题目。2. 测试用例 普通二叉树(完全二叉树,不完全二叉树) 特殊二叉树(所有节点都没有右子节点的二... 阅读全文
posted @ 2015-02-26 19:44 vincently 阅读(845) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解法:自底向上 时间复杂度O(n), 空间复杂度O(logN) 1 clas... 阅读全文
posted @ 2015-02-26 19:16 vincently 阅读(212) 评论(0) 推荐(0)
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximu... 阅读全文
posted @ 2015-02-25 20:28 vincently 阅读(126) 评论(0) 推荐(0)
摘要:Implementint sqrt(int x).Compute and return the square root ofx.解法:二分搜索 时间复杂度O(logN), 空间复杂度O(1) 1 class Solution { 2 public: 3 int mySqrt(int x)... 阅读全文
posted @ 2015-02-25 19:04 vincently 阅读(238) 评论(0) 推荐(0)
摘要:Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-02-25 18:41 vincently 阅读(643) 评论(0) 推荐(0)
摘要:本文转载自:http://www.cnblogs.com/steven_oyj/archive/2010/05/22/1741375.html一、基本概念: 所谓贪心算法是指,在对问题求解时,总是做出在当前看来是最好的选择。也就是说,不从整体最优上加以考虑,他所做出的仅是在某种意义上的局部最优解。 ... 阅读全文
posted @ 2015-02-25 11:55 vincently 阅读(1359) 评论(0) 推荐(1)
摘要:二分查找又称为折半查找,仅适用于事先已经排好序的顺序表。其查找的基本思路:首先将给定值K,与表中中间位置元素的关键字比较,若相等,返回该元素的存储位置;若不等,这所需查找的元素只能在中间数据以外的前半部分或后半部分中。然后在缩小的范围中继续进行同样的查找。如此反复直到找到为止。算法如下: 1... 阅读全文
posted @ 2015-02-18 11:30 vincently 阅读(14357) 评论(0) 推荐(0)