- 博客(12)
- 收藏
- 关注
原创 算法设计8.3
题目: 吝啬SAT问题是这样的:给定一组子句(每个子句都是其中文字的析取)和整数k,求一个最多有k个变量为true的满足赋值——如果该赋值存在。证明吝啬SAT是NP-完全问题。 解答: 首先我们要证明吝啬SAT问题是np-完全问题,我们首先要证明吝啬SAT问题是np问题,然后如果能把SAT问题规约到吝啬SAT问题,那么我们就能证明这个问题。 证明吝啬SA
2017-07-09 22:28:57 226
原创 207.Course Schedule
解题思路: 典型的拓扑排序。原理也很简单,在一个有向图中,每次找到一个没有前驱节点的节点(也就是入度为0的节点), 然后把它指向其他节点的边都去掉,重复这个过程(BFS),直到所有节点已被找到,或者没有符合条件的节点(如果图中有环存在)。 DFS的解法,也需要建立有向图,还是用二维数组来建立,和BFS不同的是,我们像现在需要一个一维数组visit来记录访问状态, 大体思路是,先建立好有向图
2017-06-11 20:59:55 168
原创 200. Number of Islands
题目:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may
2017-06-03 17:59:22 181
原创 124. Binary Tree Maximum Path Sum
实验题目: Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connecti
2017-05-23 13:18:15 170
原创 149. Max Points on a Line
实验题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Subscribe to see which companies asked this question. 实验思路: 点和方向确定一条直线。 需要两
2017-05-21 22:03:11 136
原创 65. Valid Number
题目: Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Note: It is intended for the problem statement to be
2017-04-11 17:34:28 125
原创 41. First Missing Positive
题目:寻找数组中第一个未出现的正整数,关键在于题目要求只能使用常数额外空间。 思路:虽然不能再另外开辟非常数级的额外空间,但是可以在输入数组上就地进行swap操作。 交换数组元素,使得数组中第i位存放数值(i+1)。最后遍历数组,寻找第一个不符合此要求的元素,返回其下标。整个过程需要遍历两次数组,复杂度为O(n)。 代码: class Solution { publi
2017-04-05 20:36:15 118
原创 25.Reverse Nodes in k-Group
题目:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the numbe
2017-03-26 23:07:06 174
原创 42. Trapping Rain Water
题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3
2017-03-19 12:03:18 125
原创 首页30. Substring with Concatenation of All Words
题目:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly
2017-03-12 22:33:11 196
原创 首页第17题
题目:Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. 翻译: 给一个数
2017-03-05 19:32:26 115
原创 leetcode算法第二题
问题:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a l
2017-02-25 16:40:37 332
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人