自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 收藏
  • 关注

原创 习题8.3--证明吝啬SAT是NP-完全问题

1. 题目描述吝啬SAT问题是这样描述的:给定一组子句(每个子句都是其中文字的析取)和整数k,求一个最多有k个变量为true的满足赋值——如果该赋值存在。证明吝啬SAT问题为NP完全问题。2. 问题背景为了帮助理解这个问题,我们先解释下什么是SAT问题假设我们有这样一组子句: (a⋃b⋃c)⋂(a⋃b¯)⋂(b⋃c¯)(a¯⋂c)⋂(a¯⋃b¯⋃c¯) 我们需要做的就是找到a,b,c的取值(tru

2017-07-05 16:46:16 467

原创 第13周作业2(LeetCode22)

1. 题目描述Generate ParenthesesGiven 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-05-27 23:54:20 281

原创 第13周作业1(LeetCode20)

1. 题目描述 Valid ParenthesesGiven a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “

2017-05-27 23:25:45 214

原创 第11周作业2(LeetCode16)

1. 题目描述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 e

2017-05-19 17:02:52 311

原创 第11周作业1(LeetCode31)

1. 题目描述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-05-18 19:57:52 208

原创 第12周作业2(LeetCoed26)

1. 题目描述Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place wi

2017-05-18 16:54:57 208

原创 第12周作业1(LeetCode35)

1. 题目描述Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the arra

2017-05-17 16:25:24 178

原创 第10周作业2(LeetCode2)

1. 题目描述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 re

2017-05-17 09:54:05 175

原创 第10周作业1(LeetCode1)

1. 题目描述Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the s

2017-05-16 15:50:47 170

原创 第九周作业2(LeetCode4)

1. 题目描述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: nums1 = [1,

2017-05-16 09:53:34 295

原创 第九周作业1(LeetCode14)

1. 题目描述Write a function to find the longest common prefix string amongst an array of strings.2. 解决思路我们知道字符串前缀的定义是不包括该字符串最后一个字符的其他字符的有序组合,但在这道题中,最长的公共前缀应该可以包括最后一个字符,相当于前缀加空字符串(而且这个对算法不影响)。所以这道题我主要的解题思路就

2017-05-15 17:35:25 193

原创 第八周作业2(LeetCode6)

1. 题目描述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 legibility)P A H N A P L S

2017-04-21 17:28:19 218

原创 第八周作业1(LeetCode3)

1. 题目描述(LeetCode3)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 i

2017-04-19 16:09:26 182

原创 第七周作业2(LeetCode5)

1. 题目描述(LeetCode5) Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.2. 解决思路 因为用string类型定义的字符串可以直接调用函数获得字符串的长度以及可以用数组下标的形式获得对应

2017-04-16 20:35:47 222

原创 第七周作业1(LeetCode9)

1. 问题描述(LeetCode9)Determine whether an integer is a palindrome. Do this without extra space.2. 解决思路这道题如果没有对空间的使用进行限制的话,是一道用数组可以很快就解决的题目。正是要求了不能使用额外的空间,则稍微加大了这道题的难度。不过采取逐位比较判断的方法也可以很好的解决这个问题,而这一方法的关键在于在

2017-04-13 18:45:10 434

原创 第六周作业2(LeetCode 12)

1. 题目描述(LeetCode 12)Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.2. 解决思路根据上次做的罗马数字转化为整数那一题,掌握了罗马数字的记数规则和基本的组数规则,因此我们可以很快地找到解题的突破口,即: 罗马数字的基

2017-04-09 15:23:19 173

原创 第六周作业1(LeetCode13)

1. 题目描述Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.2. 解决思路在解决这道题之前应该首先了解罗马的记数方式和组成规则。基本字符:I V X L C D M;相应的阿拉伯数字表示为 1 5 10 5

2017-03-28 22:33:59 210

原创 第五周作业2(LeetCode76)

1. 题目描述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 = “ADOBECODEBANC” T = “ABC”Minimum window is “BANC”.N

2017-03-27 11:12:31 221

原创 第五周作业1(LeetCode50)

1. 题目描述 Implement pow(x, n).Hide Tags :Binary Search ,Math2. 解决思路 我的解题方法主要是利用递归和二分,具体就是把x的n次方划分成两个x的n/2次方相乘,然后递归求解子问题,结束条件是n为0返回1。因为是对n进行二分,所以算法复杂度是O(logn)。3. 完整代码#include <stdio.h>#include <stdlib.

2017-03-25 22:24:10 218

原创 第四周作业2(LeetCode442)

1. 题目描述Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extr

2017-03-20 11:26:14 231

原创 第四周作业1(LeetCode287)

1. 题目描述Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate numb

2017-03-19 14:50:56 231

原创 第三周作业1(LeetCode53)

1. 题目描述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-12 21:45:01 161

原创 第三周作业2(LeetCode75)

1. 题目描述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-03-12 21:25:09 200

原创 第三周作业1(LeetCode53)

1. 题目描述 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,

2017-03-12 17:22:35 174

原创 欢迎使用CSDN-markdown编辑器

欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl

2017-03-12 17:12:43 198

原创 第二周作业2(LeetCode42)

1. 题目描述Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,

2017-03-04 13:29:53 264

原创 第二周作业1(LeetCode27)

题目描述Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. T

2017-03-04 10:50:28 261

原创 第一周作业2(LeetCode15)

1. 题目描述Given 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 must not contain

2017-03-04 00:32:13 261

原创 第一周作业1(LeetCode7)

1. 题目要求Reverse 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 should return 0 when the r

2017-03-03 23:38:19 300

空空如也

空空如也

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

TA关注的人

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