- 博客(19)
- 收藏
- 关注
原创 NPC问题证明
STINGY SAT is the following problem: given a set of clauses (each a disjunction of literals) and an integer k, find a satisfying assignment in which at most k variables are true, if such an assignment
2017-06-23 14:47:18
1193
原创 题解——Leetcode 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-06-14 20:02:57
340
原创 题解——Leetcode 241. Different Ways to Add Parentheses 难度:Medium
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1In
2017-06-14 19:54:20
365
原创 题解——Leetcode 240. Search a 2D Matrix II 难度:Medium
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 each
2017-06-14 19:38:16
263
原创 题解——Leetcode 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.本题需要找到数组中四个数满足
2017-06-14 19:23:25
283
原创 题解——Leetcode 16. 3Sum Closest 难度:Medium
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exa
2017-06-14 19:02:24
263
原创 题解——Leetcode 12. Integer to Roman 难度:Medium
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.本题的难点主要是罗马数字的书写规则:零不显示,1-9对应着"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX
2017-06-14 18:33:53
211
原创 题解——Leetcode 5. Longest Palindromic Substring 难度:Medium
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.题目要求最长回文子串,用动态规划。dp[j][i]表示从下标j到i之间的字符串是否是回文的。j==i时,dp[j][i] = 1i - j
2017-05-15 22:59:43
195
原创 题解——Leetcode 3. Longest Substring Without Repeating Characters 难度:Medium
Given a string, find the length of the longest substring without repeating characters.本题求最长不重复子串思想很朴素,最外层循环遍历字符串,次外层循环从外层循环当前字符位置i的后一位字符开始遍历,判断其位置j上的字符与它之前的字符是否有重复,为了遍历其之前的字符,就有了第三层循环。s[j]一旦
2017-05-15 21:31:50
209
原创 题解——Leetcode 526. Beautiful Arrangement 难度:Medium
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 ≤ i
2017-05-15 15:59:24
308
原创 题解——Leetcode 6. ZigZag Conversion 难度:Medium
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this:P A H NA P L S I I GY I RAnd then read line by line: "PAHNAPLSIIGYIR"Write the cod
2017-04-28 12:13:26
253
原创 题解——Leetcode 2. Add Two Numbers 难度:Medium
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i
2017-04-28 11:07:18
2343
1
原创 题解——Leetcode 8. String to Integer (atoi) 难度:Medium
本题要求将字符串转换为整型,需要注意以下几个问题:1. 跳过开始的所有空白字符。2. 遇到正负号时做判断。3. 当转换为整型后超过了int能表示的范围[INT_MIN, INT-MAX]。 class Solution {public: int myAtoi(string str) { int i = 0; int flag = 1;
2017-04-13 14:06:46
278
原创 题解——Leetcode 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 linei is at (i, ai) and (i, 0). Find t
2017-04-02 20:55:57
262
原创 题解——Leetcode 17.Letter Combinations of a Phone Number 难度:Medium
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.Input:Digit stri
2017-03-24 17:04:23
232
原创 题解——Leetcode 529. Minesweeper 难度:Medium
Let's play the minesweeper game (Wikipedia,online game)! You are given a 2D char matrix representing the game board.'M' represents an unrevealed mine, 'E' represents anunrevealed empty square,
2017-03-06 18:22:43
378
原创 题解——Leetcode 442. Find All Duplicates in an Array 难度:Medium
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appeartwice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra
2017-03-06 11:49:42
236
原创 题解——Leetcode 406. Queue Reconstruction by Height 难度:Medium
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), where h is the height of the person and k is the number of people in front of this
2017-02-26 12:36:30
500
原创 题解——Leetcode 419. Battleships in a Board 难度:Medium
Given an 2D board, count how many battleships are in it. The battleships are represented with'X's, empty slots are represented with'.'s. You may assume the following rules:You receive a valid bo
2017-02-26 11:52:44
243
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人