上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 16 下一页
摘要: Description A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., x 阅读全文
posted @ 2018-01-30 11:45 bw98 阅读(168) 评论(0) 推荐(0) 编辑
摘要: Description Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Sample 思路 回文串是正着读、反着读都 阅读全文
posted @ 2018-01-29 12:22 bw98 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 前言 最近在刷算法题,常常需要自定义比较函数作为作为函数对象送入 stl 中,遇到了下面的问题: 泛型算法 sort() 实现从小到大的递增关系是这么写: 而优先队列里是这么写: 同样是实现元素的递增关系即 “前一元素的x分量 < 后一元素的x分量”,为什么前一个是 “a.x < b.x”,而后一个 阅读全文
posted @ 2018-01-28 14:47 bw98 阅读(916) 评论(0) 推荐(0) 编辑
摘要: Description Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 实现链表版的 k 路归并并分析其复杂度。 思路 一看到归并且要求时间复杂度尽可 阅读全文
posted @ 2018-01-27 14:54 bw98 阅读(257) 评论(1) 推荐(0) 编辑
摘要: 6.1-1 在高度为 h 的堆中,元素最多有 2h+1 - 1 个,最少有 2h 个。注意算法导论里的高度是指深度,从 0 开始而不是从 1 开始。 6.1-2 这很好想,但是不好证明。 由已知高度为 h 的堆,它的元素个数满足 2h <= n <= 2h+1 - 1 ,解出 lg(n+1) - 1 阅读全文
posted @ 2018-01-26 23:36 bw98 阅读(317) 评论(0) 推荐(0) 编辑
摘要: Description Find the contiguous subarray within an array (containing at least one number) which has the largest sum. Input [-2,1,-3,4,-1,2,1,-5,4] Out 阅读全文
posted @ 2018-01-25 23:06 bw98 阅读(267) 评论(1) 推荐(0) 编辑
摘要: Description Mr. and Mrs. Smith are going to the seaside for their holiday. Before they start off, they need to choose a hotel. They got a list of hote 阅读全文
posted @ 2018-01-24 19:35 bw98 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 4.1-1 通过分析知由于 FIND-MAX-CROSSING-SUBARRAY 返回的是数组A最中间的两个负数组成的数组,则经过分治算法 FIND-MAXIMUM-SUBARRAY 处理后,返回的是一个长度为1的只含最大负数的数组。 4.1-2 伪代码如下: 4.1-3 性能交叉点要根据具体而定, 阅读全文
posted @ 2018-01-20 12:58 bw98 阅读(1439) 评论(0) 推荐(0) 编辑
摘要: Description We all love recursion! Don't we? Consider a three-parameter recursive function w(a, b, c): if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) 阅读全文
posted @ 2018-01-20 09:34 bw98 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 3.1-1 假设存在 h(n) = Θ(f(n)+g(n)) ,由渐进符号 Θ 的性质知存在三个正常量c1、 c2、n0,当n ≥ n0时,使得 c1·(f(n)+g(n)) ≤ h(n) ≤ c2·(f(n)+g(n)),当 h(n) = max(f(n), h(n)) 时,令 c1 = 0.5, 阅读全文
posted @ 2018-01-15 13:24 bw98 阅读(1258) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 16 下一页