上一页 1 2 3 4 5 6 7 8 9 ··· 23 下一页
摘要: auto_ptr auto_ptr是当前C++标准库中提供的一种智能指针。 auto_ptr在构造时获取某个对象的所有去(ownership),在析构时释放该对象。我们可以这样使用auto_ptr来提高代码安全性:int* p = new int(0);auto_ptr ap(p); 从此我们... 阅读全文
posted @ 2015-09-18 16:55 vincently 阅读(301) 评论(0) 推荐(0) 编辑
摘要: Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2015-09-17 21:03 vincently 阅读(286) 评论(0) 推荐(0) 编辑
摘要: 内存足够的情况: 可以使⽤用类似quick sort的思想进行,均摊复杂度为O(n),算法思想如下:• 随机选取一个元素,将比它小的元素放在它左边,比它大的元素放在右边• 如果它恰好在中位数的位置,那么它就是中位数,可以直接返回• 如果小于它的数超过一半,那么中位数一定在左半边,递归到左边处理• 否... 阅读全文
posted @ 2015-09-17 17:23 vincently 阅读(5575) 评论(0) 推荐(0) 编辑
摘要: 物理内存的管理 Linux管理物理内存是使用分页机制实现的。为了使分页机制在32位和64位体系结构下高效工作,Linux采用了一个四级分页策略。 Linux支持多种内存分配机制。分配物理内存页框的主要机制是页面分配器,它使用了著名的伙伴算法作为物理内存分配机制。 管理一块内存的基本思想如下... 阅读全文
posted @ 2015-09-17 10:53 vincently 阅读(313) 评论(0) 推荐(0) 编辑
摘要: Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return ... 阅读全文
posted @ 2015-09-15 20:55 vincently 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 0-1背包问题:有一个贼在偷窃一家商店时,发现有n件物品,第i件物品价值vi元,重wi磅,此处vi与wi都是整数。他希望带走的东西越值钱越好,但他的背包中至多只能装下W磅的东西,W为一整数。应该带走哪几样东西?这个问题之所以称为0-1背包,是因为每件物品或被带走;或被留下;小偷不能只带走某个物品... 阅读全文
posted @ 2015-09-14 10:26 vincently 阅读(11884) 评论(0) 推荐(0) 编辑
摘要: Given a non-negative integernum, repeatedly add all its digits until the result has only one digit.For example:Givennum = 38, the process is like:3 + ... 阅读全文
posted @ 2015-09-12 23:34 vincently 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> ... 阅读全文
posted @ 2015-09-12 23:14 vincently 阅读(120) 评论(0) 推荐(0) 编辑
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the... 阅读全文
posted @ 2015-09-12 17:52 vincently 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 答案是7次。1. 首先将25匹马分成5组a、b、c、d、e进行比赛。比赛的次数就是5次。得到每组的第一名,分别编号a1,b1,c1,d1,e1。2. 然后我们将每组的第一名进行比赛,得出结果。假设a1>b1>c1>d1>e1。(大于号表示a1比b1快,1表示第一名)。在这个地方我们可以推断出,a1是... 阅读全文
posted @ 2015-09-12 14:46 vincently 阅读(3614) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 23 下一页