自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 《算法概论》习题8.10

8.10 利用推广的方法证明NP-完全性。对以下每个问题,请通过证明它是本章某个NP-完全问题的推广说明它是NP-完全的。(a) 子图同构:给定两个作为输入的无向图G和H,判断G是否为H的一个子图(即删除H中的某些顶点或边后,所得的新图最多只需再修改某些顶点的名称,即可与G相同),且如果是,返回由V(G)到V(H)的相关映射。(b) 最长路径:给定图G和整数g,求G中一条长为g的简单路径。

2017-07-03 21:39:21 291 1

原创 leetCode---Gas Station

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-27 22:22:47 286

原创 leetCode--- Patching Array

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-26 15:28:07 210

原创 leetCode--- Is Subsequence

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-25 21:02:06 222

原创 leetCode---Minimum Size Subarray Sum

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-25 20:36:16 329

原创 leetCode--- Jump Game II

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-22 11:30:00 177

原创 leetCode---Invert Binary Tree

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-22 10:58:56 201

原创 leetCode---Jump Game

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-22 10:13:07 162

原创 leetCode---Arithmetic Slices

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-21 21:26:55 242

原创 leetCode---Symmetric Tree

一. 题目:Number of IslandsGiven 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 horizontall

2017-06-21 10:39:06 189

原创 leetCode---Candy

一. 题目:Remove Duplicates from Sorted Array IIFollow up for "Remove Duplicates": What if duplicates are allowed at most twice?        For example, given sorted array A = [1,1,1,2,2,3], your

2017-06-20 11:47:14 198

原创 leetCode---Search a 2D Matrix II

一. 题目:Remove Duplicates from Sorted Array IIFollow up for "Remove Duplicates": What if duplicates are allowed at most twice?    For example, given sorted array A = [1,1,1,2,2,3], your function

2017-06-20 11:15:48 192

原创 leetCode---Range Sum Query - Immutable

一. 题目:Remove Duplicates from Sorted Array II     Follow up for "Remove Duplicates": What if duplicates are allowed at most twice?    For example, given sorted arrayA = [1,1,1,2,2,3], your

2017-06-15 11:06:26 186

原创 leetCode---Number of Islands

一. 题目:Remove Duplicates from Sorted Array II         test01二. 思路分析          段落儿

2017-06-15 10:15:24 260

原创 leetCode---Assign Cookies

一. 题目:Remove Duplicates from Sorted Array II      Follow up for "Remove Duplicates": What if duplicates are allowed at most twice?二. 思路分析    因为题目是所给数组已经排序的数组,所以加一个变量记录一下元素出现的次数,这样加一个变量即可解决

2017-06-15 09:51:11 176

原创 leetCode---Increasing Triplet Subsequence

一. 题目:test01    Follow up for "Remove Duplicates": What if duplicates are allowed at most twice?二. 思路分析     Follow up for "Remove Duplicates": What if duplicates are allowed at most twice?

2017-06-15 09:27:57 188

原创 leetCode---Remove Duplicates from Sorted Array II

一. 题目:Remove Duplicates from Sorted Array II    Follow up for "Remove Duplicates": What if duplicates are allowed at most twice?    For example, given sorted arrayA = [1,1,1,2,2,3], your fun

2017-06-13 10:26:04 189

原创 leetCode---Reverse Words in a String III

一. 题目:Reverse Words in a String IIIGiven a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example

2017-06-04 18:19:09 244

原创 leetCode---Array Partition I

一. 题目:Array Partition IGiven an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for

2017-06-04 17:52:36 237

原创 leetCode---Rotate Array

一. 题目:Rotate Array Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note:Try to come up as ma

2017-05-23 21:42:18 229

原创 leetCode---Intersection of Two Arrays

一. 题目:Intersection of Two ArraysIntersection of Two Arrays IGiven two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].

2017-05-19 13:55:49 236

原创 leetCode---Valid Anagram

一. 题目:Valid AnagramGiven two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.

2017-05-19 13:35:10 189

原创 leetCode---Implement pow(x, n)

一. 题目:Implement pow(x, n)Implement pow(x, n)二. 思路分析这里n是整数,注意可能是负数,因此需要先将其转化成正数。若直接用循环的方法做,会产生超时错误。我们可以这么做。比如求2^6,我们需要求2^(2*3)=4^3=4*4^2,这样时间复杂度为O(logn)。注意几个特殊的情况,当n==1时,返回x本身,当n==0时,返回1,

2017-05-09 16:54:27 233

原创 leetCode---Implementint sqrt(int x).

一. 题目:Implementint sqrt(int x).Implementint sqrt(int x).Compute and return the square root of x.二. 思路分析      这道题很巧妙的运用了二分查找法的特性,有序,查找pos(在这道题中pos=value),找到返回pos,找不到返回

2017-05-09 16:30:01 291

原创 leetCode---Container With Most Water

一. 题目:Container With Most WaterGiven 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 lin

2017-04-27 20:49:29 407

原创 leetCode---Subsets II

一. 题目:Subsets IIGiven a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets. For example,If nums

2017-04-25 22:05:36 354

原创 leetCode---Subsets

一. 题目:SubsetsGiven a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets. For example,If nums = [1,2,3], a solution is:

2017-04-25 21:55:30 192

原创 leetCode---Merge k Sorted Lists

一. 题目:Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.二. 思路分析借鉴归并排序的方法,自顶向下,先递归的对链表的前半部分和后半部分进行归并排序,最后再m

2017-04-19 11:00:03 183

原创 leetCode---Remove Nth Node From End of List

一. 题目:Remove Nth Node From End of List Given 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 r

2017-04-18 22:03:14 226

原创 leetCode---3Sum Closest

一. 题目:3SumGiven an array S of n integers, find three integers inS such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input wou

2017-04-07 15:30:32 262

原创 leetCode---3Sum

一. 题目:3SumGiven an array S of n integers, are there elementsa, 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

2017-04-07 15:04:56 190

原创 leetCode---Longest Substring Without Repeating Characters

一. 题目:Longest Substring Without Repeating Characters          Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "ab

2017-03-27 20:53:18 262

原创 leetCode---Add Two Numbers

一. 题目:Add Two NumbersYou 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 t

2017-03-27 20:18:47 216

原创 leetCode---Increasing Subsequences

一. 题目:Increasing Subsequences Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should

2017-03-18 20:43:27 293

原创 leetCode---Target Sum

一. 题目:Target SumYou 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 s

2017-03-11 23:27:49 345

原创 leetCode---Majority Element

一. 题目:Majority Element      Given an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋ times.You may assume that the array is

2017-03-04 20:34:06 321

原创 leetCode---Maximum Subarray

一. 题目:Maximum SubarrayFind 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 conti

2017-02-23 20:23:10 233

空空如也

空空如也

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

TA关注的人

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