- 博客(30)
- 收藏
- 关注
原创 吝啬SAT问题是NP完全的证明
吝啬SAT问题的定义: 给定一组子句和整数k,求一个最多有k个变量为true的满足赋值。 而我们已知SAT是NP完全的. 现在我们只需要证明他们一方可以推出另一方即可。 我们归约,假设吝啬SAT不是NP完全的,那么一个有n个变量的SAT问题有多项式时间的算法,显然矛盾,所以,吝啬SAT是NP完全的
2017-12-28 17:14:28
276
原创 Delete and Earn
题目描述: Given an array nums of integers, you can perform operations on the array.In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal
2017-12-26 20:47:04
305
原创 Strange Printer
题目描述: There is a strange printer with the following two special requirements:The printer can only print a sequence of the same character each time. At each turn, the printer can print new characters
2017-12-22 20:34:27
243
原创 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-12-17 10:45:04
123
原创 Word Ladder
题目描述: Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at
2017-12-11 11:11:54
147
原创 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-12-02 10:47:38
118
原创 Task Scheduler
题目描述: Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task c
2017-11-26 17:08:01
187
原创 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 of k, that is, sums
2017-11-20 21:07:55
196
原创 Candy
题目描述: There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one
2017-11-15 21:20:16
138
原创 Coin Change
题目描述: You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of
2017-11-10 16:37:53
205
原创 Minimum ASCII Delete Sum for Two Strings
题目描述: Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.Example 1: Input: s1 = “sea”, s2 = “eat” Output: 231 Explanation: Deleting “s” from “sea” a
2017-11-04 11:22:32
153
原创 Integer Break
题目描述: Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, r
2017-11-04 09:49:22
120
原创 Counting Bits
题目描述: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5
2017-10-29 22:29:13
167
原创 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 how
2017-10-29 22:18:43
180
原创 Unique Paths
题目描述: A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach th
2017-10-23 08:56:44
176
原创 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-10-23 08:47:26
140
原创 Next Permutation
题目描述: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possib
2017-10-15 18:36:45
145
原创 Jump Game
题目描述: 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 if
2017-10-15 18:26:43
164
原创 Sort Colors
题目描述: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integer
2017-10-15 18:20:33
158
原创 Generate Parentheses一道普通dfs题目
题目描述: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ “((()))”, “(()())”, “(())()”, “()
2017-10-09 08:40:13
131
原创 Gray Code
题目描述 The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2017-10-09 08:36:15
128
原创 Jump Game II一道优化bfs题
题目描述: 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 is
2017-10-03 21:12:09
531
原创 Search for a Range一打简单的二分题
题目描述: Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the ta
2017-10-03 21:06:48
240
原创 Wildcard Matching
题目描述: ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype sh
2017-09-25 08:47:19
112
原创 Friend Circles
这是一道leetcode上的题目,题目要求大概是要找出有多少个连通块, 一开始想用些奇技淫巧,后来还是用了DFS暴力解决。 原题如下: There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For examp
2017-09-24 17:00:27
172
原创 一道stack的题目
原题如下 Given an encoded string, return it’s decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is
2017-09-23 17:20:03
233
原创 一道简单的题目
这是一道leetcode的题目, 描述如下: Given an unsorted integer array, find the first missing positive integer.For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.Your algorithm should run in O(n) time a
2017-09-18 08:47:34
439
原创 一道简单的递归题
题目描述如下: Implement pow(x, n). 非常简单的一句话。 但這其中有一些坑。 就是INT_MIN的相反数,会溢出。 所以现将输入的参数强行转换为long防止这个问题。 代码如下: double myPow(double x, int n) { if(x==0) return 0; long temp=n; if
2017-09-17 17:00:33
313
原创 一道奇怪的分治问题
原题是这样的: Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire i
2017-09-14 21:35:36
455
原创 关于leetcode Minimum Window Substring的思考
关于leetcode Minimum Window Substring的思考此题的题目如下: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example, S = “ADOBECODEB
2017-09-07 21:24:22
230
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人