上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 23 下一页
摘要: 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 阅读(225) 评论(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 阅读(632) 评论(0) 推荐(0) 编辑
摘要: 本文转载自:http://www.cnblogs.com/steven_oyj/archive/2010/05/22/1741375.html一、基本概念: 所谓贪心算法是指,在对问题求解时,总是做出在当前看来是最好的选择。也就是说,不从整体最优上加以考虑,他所做出的仅是在某种意义上的局部最优解。 ... 阅读全文
posted @ 2015-02-25 11:55 vincently 阅读(1344) 评论(0) 推荐(1) 编辑
摘要: 二分查找又称为折半查找,仅适用于事先已经排好序的顺序表。其查找的基本思路:首先将给定值K,与表中中间位置元素的关键字比较,若相等,返回该元素的存储位置;若不等,这所需查找的元素只能在中间数据以外的前半部分或后半部分中。然后在缩小的范围中继续进行同样的查找。如此反复直到找到为止。算法如下: 1... 阅读全文
posted @ 2015-02-18 11:30 vincently 阅读(14210) 评论(0) 推荐(0) 编辑
摘要: 地址解析协议(Address Resolution Protoclol),其基本功能为通过目标设备的IP地址,查询目标设备的MAC地址,以保证通信的顺利。它是IPV4中网络层必不可少的协议。不过在IPV6中已经不再适用,并被邻居发现协议(NDP)所代替。 当一台主机把以太网数据帧发送到位于同一... 阅读全文
posted @ 2015-01-27 10:34 vincently 阅读(520) 评论(0) 推荐(0) 编辑
摘要: 一、什么是分治 有很多算法是递归的:为了解决一个给定的问题,算法要一次或多次递归调用其自身来解决的子问题。这些算法通常采用分治策略:将原问题划分为n个规模较小而结构与原问题相似的子问题;递归地解决这些子问题,然后再合并其结果,就得到原问题的解。 习惯上,在正文中至少含有两个递归调用的例程叫作... 阅读全文
posted @ 2015-01-24 20:02 vincently 阅读(1005) 评论(0) 推荐(0) 编辑
摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ... 阅读全文
posted @ 2015-01-21 22:03 vincently 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:递归的思路。思路与重建二叉树类似。时间复杂度O(n), 空间复杂度O(logN) 1 /** 2 ... 阅读全文
posted @ 2015-01-20 20:14 vincently 阅读(210) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文
posted @ 2015-01-20 11:44 vincently 阅读(285) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文
posted @ 2015-01-18 22:40 vincently 阅读(215) 评论(0) 推荐(0) 编辑
上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 23 下一页