- 博客(9)
- 收藏
- 关注
原创 算法概论 习题8.20
本篇为算法课期末作业。 题目是8.20. 原题:在一个无向图G=(V,E)中,我们称为一个占优集,是指每个都属于D或者D中一个节点为邻。在占优集问题中,输入为一个图和预算b,目标是求图的一个规模不超过b的控制集——如果该集存在。证明该问题是NP-完全的。 解答:可以将顶点覆盖问题归约到支配集问题。若要在图G(V, E)中求得不大于b的一个顶点覆盖,可以先对图G 做一个预处理:对每条边
2017-07-13 18:07:12 368
原创 134. Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to
2017-06-20 23:30:46 281
原创 542. 01 Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example 1: Input: 0 0 0 0 1 0 0 0 0 Output: 0 0 0 0 1 0 0
2017-06-20 22:59:39 306
原创 133. Clone Graph(DFS)
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are labeled uniquely. We use # as a separator for each
2017-06-20 19:04:03 277
原创 210. Course Schedule II(DFS)
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2017-06-17 11:49:38 358
原创 388. Longest Absolute File Path
原题过长就不拷过来了,题目要求是找出文件系统中的最长绝对路径 原题地址:https://leetcode.com/problems/longest-absolute-file-path/#/description 输入的是一个字符串,如字符串"dir\n\tsubdir1\n\tsubdir2\n\t\tfile.txt"表示如下的文件系统: dir subdir1 subdir2 f
2017-06-10 19:02:29 334
原创 215. Kth Largest Element in an Array
原题目是 Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return
2017-06-10 18:34:52 172
原创 23. Merge k Sorted Lists
原本想找一篇与分治策略有关的题目,便搜索了merge类的题目挑一篇做。 题目是Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 大意是将K个已经排好序的链表合并成一个链表。一开始打算运用分治法将其一分二,二分四分成n个基本子问题来求解,但由于链
2017-06-04 22:11:35 208
原创 找出数组中唯二出现一次的数
原题取自https://leetcode.com/problems/single-number-iii/?tab=Description 题目要求找出数组中唯二出现一次的数,其余数均只出现两次。 要求做到算法的时间复杂度为O(n) 解题最直接的方法是计算出数组中每个数出现的次数,然后取其中出现一次的,但其算法复杂度不满足题目要求 这里采用异或计算的方法来求解 由于 A ^A = 0,,A
2017-02-26 13:46:29 793
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人