- 博客(36)
- 收藏
- 关注
原创 NP 完全问题8.3
首先,我们可以在多项式时间内验证stingy sat的解是否正确。将问题归约到stingy sat。假设一个stingy sat的实例(f,k),一组赋值x。(1)令x为f的解,那么有最多k个变量为真,x给(f,k)的值也为真,则x为(f,k)的解。(2)令x为(f,k)的解,易知x为f的解。所以stingy sat为一个NP完全问题。
2017-07-07 11:00:17 282
原创 63. Unique Paths II Medium
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the
2017-06-20 12:07:30 196
原创 377. Combination Sum IV Medium
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.思路:找到子问题为:target减少的时候一共有多少中排列方式。对于target有多少种
2017-06-13 22:48:21 196
原创 392. Is Subsequence Medium
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 and t. t is potentially a very long (length ~= 500,000) strin
2017-06-11 11:52:03 156
原创 413. Arithmetic Slices Medium
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequenc
2017-06-10 22:23:38 195
原创 139. Word Break Medium
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may as
2017-06-09 18:30:19 227
原创 416. Partition Equal Subset Sum Medium
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.思路:题目要求是否有子列使得子列的和为sum
2017-06-09 17:20:02 175
原创 467. Unique Substrings in Wraparound String Medium
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".Now we ha
2017-06-08 17:07:08 178
原创 95. Unique Binary Search Trees II Medium
Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below.
2017-06-08 16:35:08 199
原创 91. Decode Ways Medium
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu
2017-06-08 00:03:02 256
原创 474. Ones and Zeroes Medium
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 and n 1s respectively. On the ot
2017-06-07 20:17:37 259
原创 486. Predict the Winner Medium
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a
2017-06-07 18:49:13 197
原创 494. Target Sum Medium
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-06-07 17:34:02 202
原创 327. Count of Range Sum Hard
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j),
2017-05-14 16:29:39 203
原创 514. Freedom Trail Hard
In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring", and use the dial to spell a specific keyword in order to open the door.
2017-05-02 22:59:16 615
原创 315. Count of Smaller Numbers After Self Hard
You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].
2017-05-01 16:45:14 202
原创 312. Burst Balloons Hard
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get num
2017-04-22 23:22:48 328
原创 23. Merge k Sorted Lists Hard
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:这和merge两个数组思维一样,通过一个辅助链表将比较的两个链表中较小的数存起来,最终得到结果。把每次得到的新链表存在lists的最后,并且去除lists中比较的两个链表,当list
2017-04-17 13:39:12 286
原创 45. Jump Game II Hard
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i
2017-04-04 21:30:24 162
原创 18. 4Sum Medium
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution
2017-04-04 21:25:53 181
原创 123. Best Time to Buy and Sell Stock III Hard
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You ma
2017-03-27 13:41:25 150
原创 299. Bulls and Cows Medium
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint
2017-03-27 13:27:20 166
原创 525. Contiguous Array Medium
Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. 思路:为了找0,1数量相同的最长子列,题目也有tag使用hash表,我们用map充当hash表,希望用和的形式表示出0,1的数量相同,我们将数组里的0全部换为-1,这样的话-1
2017-03-19 18:49:32 251
原创 57. Insert Interval Hard
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.
2017-03-19 18:38:30 186
原创 166. Fraction to Recurring Decimal Medium
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.
2017-03-12 18:03:55 162
原创 49. Group Anagrams Medium
Given an array of strings, group anagrams together.思路:将字符相同的子串归为一类。由于各字符是乱序的,我们先将个string按照字符顺序的排序,然后使用hash表就可以判断哪些string应该归为一类。用map将一类的string储存起来,最后全部归在同一个vector下就可以了。class Solutio
2017-03-12 17:59:44 187
原创 128. Longest Consecutive Sequence Hard
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3
2017-03-12 17:54:54 218
原创 154. Find Minimum in Rotated Sorted Array II Hard
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.The array may cont
2017-03-12 17:50:02 161
原创 187. Repeated DNA Sequences Medium
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2017-03-04 22:21:55 185
原创 84. Largest Rectangle in Histogram Hard
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.思路:本体最直接的想法就是遍历每一种情况,通过比较来获得矩形的最大值。如
2017-03-04 22:01:28 162
原创 152. Maximum Product Subarray Medium
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 contiguous subarray [2,3] has the larges
2017-03-04 21:48:53 202
原创 120. Triangle Medium
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.思路:题目就是说从三角形顶端向下走,找到一条路使得和最小。这是个二维动态规划问题,我们将其分解为多个类似的子问题:寻找每个点到最低端的最
2017-03-04 21:33:33 159
原创 414. Third Maximum Number Easy
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).思路:由于复杂度限制在O(n),直接遍历寻找最
2017-02-25 21:23:13 217
原创 4. Median of Two Sorted Arrays Hard
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).思路:将两个数组合成一个数组,从小到大排序,
2017-02-25 20:40:26 154
原创 11. Container With Most Water Medium
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2017-02-25 20:34:35 176
原创 55. Jump Game Medium
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i
2017-02-25 20:23:34 303
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人