- 博客(19)
- 收藏
- 关注
原创 算法概论第八章 NP完全问题 习题证明
8.3 吝啬SAT问题是这样的: 给定一组字句(每个句子都是其中文字的析取)和整数k, 求一个最多有k个变量为true的满足赋值, 如果该赋值存在. 证明吝啬SAT问题是NP完全问题.证明: 考虑将SAT归约为旅行商问题(TSP), 如果可以确定一条经过所有变量的路径, 且变量值为true的个数不超过k, 则存在这样的赋值, 反之, 则不存在; 证毕.
2017-07-05 19:52:52
1437
原创 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 00 1 00 0 0Output:0 0 00 1 00 0
2017-06-26 10:06:22
339
原创 455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a coo
2017-06-19 16:22:37
275
原创 474. Ones and Zeroes
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s andn 1s respectively. On the other
2017-06-11 19:18:17
266
原创 523. Continuous Subarray Sum
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple ofk, that is, sums up to
2017-06-04 01:14:36
321
原创 378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not t
2017-05-28 21:28:05
271
原创 372. Super Pow
Your task is to calculate ab mod 1337 wherea is a positive integer and b is an extremely large positive integer given in the form of an array.Example1: a = 2b = [3]Result: 8Example2:
2017-05-22 00:10:10
288
原创 27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.Th
2017-05-15 01:24:51
225
原创 392. Is Subsequence
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s andt. t is potentially a very long (length ~= 500,000) stri
2017-05-06 15:44:12
242
原创 494. Target Sum
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.Find out
2017-04-30 17:10:31
407
原创 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], ther
2017-04-23 09:36:58
302
原创 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "
2017-04-16 13:23:22
276
原创 448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.
2017-04-09 19:22:04
217
原创 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne
2017-04-02 23:31:45
363
原创 8. String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca
2017-03-26 13:30:21
673
原创 35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2017-03-18 14:24:09
232
原创 240. Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in
2017-03-12 16:37:48
277
原创 493. Reverse Pairs
Given an array nums, we call (i, j) an important reverse pair if i and nums[i] > 2*nums[j].You need to return the number of important reverse pairs in the given array.Example1:Input: [1
2017-03-05 21:37:31
432
原创 1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sam
2017-02-26 20:49:48
250
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人