自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(36)
  • 资源 (1)
  • 收藏
  • 关注

原创 3SAT课本题目 8.20

Solution: 将顶点覆盖问题归约到支配集问题。如果要在图G(V,E)中求一个不大于b的顶点覆盖,按照以下规则预处理图G:给条边(u,v)∈E加上辅助顶点w,还有两条边(u,w)和(v,w),比如: 对于新图G’,如果原图G有不大于b的顶点覆盖,那么它也是G’的一个支配集。如果G’存在不大于b的支配集,预处理后也能得到G的不大于b的顶点覆盖。 设支配集为D,对于每条边(u,v)还有相应

2018-01-10 14:51:53 321

原创 22. Generate Parentheses

Problem:22. Generate ParenthesesDescriptionGiven 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-12-31 21:21:14 145

原创 19. Remove Nth Node From End of List

Problem19. Remove Nth Node From End of ListQuestionGiven a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After

2017-12-23 10:54:15 203

原创 16. 3Sum Closest

Problem16. 3Sum ClosestQuestionGiven 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

2017-12-23 10:51:43 135

原创 18. 4Sum

Problem18. 4SumQuestionGiven 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.No

2017-12-23 10:46:22 142

原创 17. Letter Combinations of a Phone Number

Problem17. Letter Combinations of a Phone NumberQuestionGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the tel

2017-12-17 20:48:50 131

原创 15. 3Sum

Problem15. 3SumQuestionGiven an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set

2017-12-17 20:47:00 136

原创 LeetCode [10. Regular Expression Matching]

Problem10. Regular Expression MatchingQuestionImplement regular expression matching with support for ‘.’ and ‘*’.'.' Matches any single character.'*' Matches zero or more of the preceding element.The

2017-12-09 21:22:10 135

原创 LeetCode [11. Container With Most Water]

Problem11. Container With Most WaterQuestionGiven 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 l

2017-12-08 22:23:42 122

原创 LeetCode [12. Integer to Roman]

Problem12. Integer to RomanQuestionGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路罗马数字的详细介绍请点击这里罗马数字思路比较简单,把数字拆解为千百十个位,每个位都对应一个罗马表示,最后把所有罗马表

2017-12-08 08:11:29 114

原创 算法期中 最小和

Problem从数列A[0], A[1], A[2], …, A[N-1]中选若干个数,要求对于每个i(0<=i < N-1),A[i]和A[i+1]至少选一个数,求能选出的最小和.1 <= N <= 100000, 1 <= A[i] <= 1000请为下面的Solution类实现解决上述问题的函数minSum,函数参数A是给出的数列,返回值为所求的最小和.例1:A = {2, 5, 2},答案为

2017-12-07 09:21:39 466

原创 算法期中 最小差

Problem:对于一个整数数列A[0], A[1], …, A[N-1],要求在其中找两个数,使得它们的差的绝对值最小.2 <= N <= 100, -1000 <= A[i] <= 1000.请实现下面Solution类中计算minDifference(A)的函数,返回值为能得到的最小差.class Solution {public: int minDifference(vect

2017-12-04 00:15:00 251

原创 算法期中 合并二叉树

Problem:输入两个二叉树T1和T2,要求对T1和T2进行合并. 合并是指将二叉树同一位置节点上的数求和,作为合并后二叉树相应位置节点的数值. 如果某个位置上只有一个二叉树有节点,则合并后的二叉树对应位置上的节点上的数值就等于这个节点上的数值.例如: T1 T2 1

2017-12-04 00:12:54 283

原创 算法期中 最近的0

Problem:输入一个N*M的01矩阵A,对矩阵的每个位置,求至少经过多少步可以到达一个0. 每一步可以往上下左右走一格.请为下面的Solution类实现解决这一问题的函数nearestZero,函数参数A为给出的01矩阵,A的行数和列数均不大于100. 函数的返回值是问题的答案.例如: A= 1 1 1 0 1 1 0 0 1答案为 1 2 3 0 1 2 0 0 1Code:cl

2017-12-04 00:09:44 572

原创 算法期中 最长公共子串

Problem:给定两个字符串x = x­1x­2…x­n和y = y­1y­2…ym, 请找出x和y的最长公共子串的长度,也就是求出一个最大的k,使得存在下标i和j有x­ix­i+1…x­i+k-1 = yjy­j+1…y­j+k-1.x和y只含有小写字母,长度均在1和1000之间.请为下面的Solution类实现解决上述问题的函数longestSubstring,函数的参数x和y为给出的两个单词

2017-12-04 00:07:52 143

原创 算法期中 拓补序

Problems:在图论中,拓扑序(Topological Sorting)是一个有向无环图(DAG, Directed Acyclic Graph)的所有顶点的线性序列. 且该序列必须满足下面两个条件:每个顶点出现且只出现一次.若存在一条从顶点 A 到顶点 B 的路径,那么在序列中顶点 A 出现在顶点 B 的前面.对于一个含有n个节点的有向无环图(节点编号0到n-1),输出它的一个拓扑序.图

2017-12-04 00:02:58 247

原创 [算法期中] 分组

Problems:对于一个整数数列A[0], A[1], …, A[N-1]进行分组,要求每组1到2个数,并且同组之和不能大于w. 求最少可以分成多少组.1 <= N <= 100000, 1 <= A[i] <= w <= 1000000000.例1:当A = {2, 5, 4, 3}, w = 5, minPartition(A, w)返回3. 将2和3放一组,4和5各自单独作为一组,共3组.例

2017-12-03 23:24:41 223

原创 LeetCode [6. ZigZag Conversion]

Problem: 6. ZigZag ConversionQuestion:The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better l

2017-11-26 15:23:53 139

原创 LeetCode [Median of Two Sorted Arrays]

Problem:4. Median of Two Sorted ArraysQuestionThere 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 b

2017-11-26 14:48:08 254 1

原创 LeetCode [70. Climbing Stairs]

Problem:70. Climbing StairsQuestionYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?No

2017-11-05 15:41:59 152

原创 LeetCode [53. Maximum Subarray]

Problem:53. Maximum SubarrayQuestionFind 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 co

2017-11-05 15:37:45 127

原创 LeetCode [303. Range Sum Query - Immutable]

Problem:303. Range Sum Query - ImmutableQuestionGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0

2017-11-05 15:28:08 132

原创 Leetcode [210. Course Schedule II]

Problem:210. Course Schedule IIQuestionThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take

2017-11-05 14:50:30 153

原创 Leetcode [300. Longest Increasing Subsequence]

Problem:300. Longest Increasing SubsequenceQuestionGiven 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

2017-10-28 22:20:44 138

原创 Leetcode [8. String to Integer (atoi)]

Problem:8. String to Integer (atoi)QuestionImplement 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 y

2017-10-28 21:57:41 370

原创 Leetcode [609. Find Duplicate File in System]

Problem:609. Find Duplicate File in SystemQuestionGiven a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of dupl

2017-10-21 18:23:30 180

原创 Leetcode [207. Course Schedule]

Problem:207. Course ScheduleQuestionThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take cou

2017-10-21 17:24:01 176

原创 Leetcode [Longest Palindromic Substring]

Problem:Longest Palindromic SubstringQuestionGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.思路Manacher算法对于一个字符串,除了直接遍历以外,也可以用扩展的方式来找字

2017-10-10 17:54:38 192

原创 Leetcode [Merge Two Sorted Lists]

Merge Two Sorted Lists

2017-10-10 17:01:23 161

原创 Leetcode [Valid Parentheses]

Problem : Valid ParenthesesQuestionGiven a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order,

2017-10-10 16:57:31 177 1

原创 Leetcode [Longest Common Prefix]

Problem:Longest Common PrefixQuestionWrite a function to find the longest common prefix string amongst an array of strings.思路寻找一连串字符串的最长共同前缀。 我第一想法是,首先假定第一个字符串就是最大前缀(如果这个数组为空那这个字符串就是空)。依次向后调整这个前缀。有以下几

2017-09-24 19:47:14 187

原创 Leetcode [Roman to Integer]

Problem:Roman to IntegerQuestionGiven a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.思路 罗马数字共有7个,即Ⅰ(1)、Ⅴ(5)、Ⅹ(10)、Ⅼ(50)、Ⅽ(100)、Ⅾ(500)和Ⅿ(1000)。按照

2017-09-24 19:41:05 199

原创 Leetcode [Palindrome Number]

Problem:Palindrome NumberQuestion:Determine whether an integer is a palindrome. Do this without extra space.思路题目要求在不使用多余空间的情况下判断一个整数是否是回文的(意即正着数和倒着数是一样的)。 直接用一个循环,每次取最高位和最低位比较,如果不相等就不用向下判断了,如果相等就继续判断,

2017-09-24 19:27:47 143

原创 Leetcode [Reverse Integer]

Problem:Reverse IntegerQuestionReverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Note: The input is assumed to be a 32-bit signed integer. Your function s

2017-09-16 15:25:37 170

原创 Leetcode [Longest Substring Without Repeating Characters]

Problem:Longest Substring Without Repeating CharactersQuesitonGiven a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”,

2017-09-16 15:21:37 149

原创 Leetcode [Add Two Numbers]

Problem:Add Two NumbersQuestionYou 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. A

2017-09-11 13:29:29 213

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除