- 博客(26)
- 收藏
- 关注
原创 Exact 4SAT问题是NP完全的证明
课后习题8.8,证明4SAT是NP完全的 总体思路是将3SAT问题归约到4SAT问题,这样就可以证明EXACT 4SAT是NP完全的。对于一个3SAT问题实例中的子句,可以通过如下方式转换为EXACT 4SAT 如果存在重复的文字,我们可以只保留其中一个,如x∨y∨y∨y x \vee y \vee y \vee y变为x∨y x \vee y 如果子句中同时存在xx和¬x\lnot x这两种
2017-07-04 23:46:58 477
原创 Leetcode题解 - 337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a tour,
2017-07-04 22:40:58 214
原创 Leetcode题解 - 565. Array Nesting
A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1]. Sets S[K] for 0 <= K < N are defined as follows: S[K] = { A[K], A[
2017-07-04 22:12:17 257
原创 Leetcode题解 - 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 “b”, with the le
2017-07-04 22:00:55 207
原创 Leetcode题解 - 452. Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coordina
2017-07-04 21:03:54 170
原创 Leetcode题解 - 322. 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 money c
2017-07-04 20:09:07 225
原创 Leetcode题解 - 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 assume
2017-06-16 14:38:21 289
原创 Leetcode题解 - 61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 链接先遍历一次链表找到链表长度,根据要
2017-06-04 21:43:53 171
原创 Leetcode题解 - 20. Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]{}” are all valid
2017-06-04 21:39:13 198
原创 Leetcode题解 - 150. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: [“2”,
2017-05-22 11:13:45 283
原创 Leetcode题解 - 554. Brick Wall
here is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the b
2017-05-15 11:27:28 401
原创 Leetcode题解 - 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. 链接给定的字符串存在一个数组中,将第一个字符串作为参考,把后续的字符串依次与strs[0]进行比较即可,双重循环即可完成。class Solution { public: string longestCommonPrefix(
2017-05-08 10:20:02 198
原创 Leetcode题解 - 151. Reverse Words in a String
Given an input string, reverse the string word by word. For example, Given s = “the sky is blue”, return “blue is sky the”. Update (2015-02-12): For C programmers: Try to solve it in-pla
2017-05-03 10:19:33 285
原创 Leetcode题解 - 22. Generate Parentheses
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-04-21 14:09:53 268
原创 Leetcode题解 - 89. 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 g
2017-04-14 15:32:21 310
转载 Leetcode题解 - 4. Median of Two Sorted Arrays
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)). Example 1: nu
2017-04-10 11:33:29 292
原创 Leetcode题解 - 55. 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
2017-03-31 15:11:53 248
原创 Leetcode题解 - 445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it
2017-03-31 15:02:47 266
原创 Leetcode题解 - 208. Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z. 戳我Trie即字典树或者前缀树,如给出字符串”abc”,”ab”,”bd”,”dda”,根据该字符串序列构建一棵
2017-03-31 14:32:41 289
原创 Leetcode题解 - 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = “leetcode” return 0. s = “loveleetcode”, return 2.
2017-03-24 14:02:56 200
原创 Leetcode题解 - 56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 链接把交叉的区间进行合并,比较简单的方法就是先把给定的区间按照左边元素的大小进行排序,然后两两相邻
2017-03-24 13:48:00 432
原创 Leetcode题解 - 495. Teemo Attacking
In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning time
2017-03-24 13:42:23 478
原创 Leetcode题解 - 139. Word Break
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 assum
2017-03-21 17:44:22 284
原创 Leetcode题解 - 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return 5
2017-03-11 20:31:56 258
原创 Leetcode题解 - 53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1]
2017-03-07 12:50:01 275
原创 Leetcode题解 - 461. Hamming Distance
描述见链接其实本质上很简单就是一个位运算的题目,将两个数按位异或之后统计二进制结果中的数字1的个数就行,代码如下:class Solution { public: int hammingDistance(int x, int y) { int z=x^y; int count=0; while((z!=0)){ if(z%2==1)
2017-02-25 17:55:42 191
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人