自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 算法概论课后习题

8.8在精确的4SAT(EXACT 4SAT)问题中,输入为一组子句,每个子句都是恰好4个文字的析取,且每个变量最多在每个子句中出现一次。目标是求它的满足赋值——如果该赋值存在。证明4SAT是NP-完全问题。证明:显然,EXACT 4SAT属于NP问题。 现在通过将3SAT归约到EXACT 4SAT来证明后者的 NP 完全性。 对于任意一个 3SAT 实例,如果其中某个子句中包含了同一个文字多次

2017-06-21 09:16:39 926

原创 leetcode:494. Target Sum

You 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 symbol.Find out how many w

2017-05-17 10:50:57 225

原创 leetcode:392. Is Subsequence

Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, an

2017-05-17 10:32:35 186

原创 leetcode:486. Predict the Winner

Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a

2017-05-09 21:54:07 207

原创 leetcode:343. Integer Break

Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return 1

2017-05-04 10:37:25 166

原创 leetcode:413. Arithmetic Slices

A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:

2017-04-19 21:26:53 185

原创 leetcode:338. Counting Bits

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you sh

2017-04-19 20:37:02 265

原创 leetcode:507. Perfect Number

We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns true when it is a perfect n

2017-04-16 23:18:38 341

原创 28. Implement strStr()

Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题意&解题思路如题,直接用KMP算法解决,代码如下:class Solution { public: int strStr(string hays

2017-04-09 20:43:38 146

原创 87. Scramble String

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = “great”: great / \ gr eat

2017-04-09 19:57:58 138

原创 leetcode:227. Basic Calculator II

Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should trunca

2017-04-09 18:32:24 229

原创 leetcode:115. Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be non

2017-03-21 17:35:16 165

原创 leetcode:332. Reconstruct Itinerary

Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus

2017-03-21 16:07:34 168

原创 leetcode:72. Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:

2017-03-19 21:46:21 174

原创 leetcode:67. Add Binary

Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 题意&解题思路: 字符串形式的二进制相加,暴力解决。注意处理多余的前导零。代码如下: class Solution { public: st

2017-03-19 19:54:42 159

原创 leetcode:49. Group Anagrams

Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],  Return: [ ["ate", "eat","tea"], ["nat","tan"], ["bat"] ] Note: Al

2017-03-19 18:58:36 141

原创 leetcode:17. Letter Combinations of a Phone Number

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 st

2017-03-19 17:35:07 146

原创 leetcode:459. Repeated Substring Pattern

Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engli

2017-03-19 16:17:12 179

原创 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-03-19 15:43:27 155

原创 leetcode:125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a

2017-03-19 15:11:37 147

原创 leetcode:44. Wildcard Matching

Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. '*' Matches any sequence of characters (including the empty sequence). The matching should cov

2017-03-13 16:50:20 139

原创 leetcode:468. Validate IP Address

Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in dot-decimal notation, which consists of four deci

2017-03-13 14:43:43 602

原创 leetCode:493. Reverse Pairs

Given an array nums, we call (i, j) an important reverse pair if i  and nums[i] > 2*nums[j]. You need to return the number of important reverse pairs in the given array. 解题思路: 1.归并排序 用

2017-03-05 22:20:37 439

原创 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-05 14:33:50 232

原创 leetcode: 11. Container With Most Water

题意: 输入n个数,每个数的值a[i]为该数的高(a[i] >= 0),其位置为该数的输入顺序(间隔为1),要求从这堆输入的数中找到两个高,使得这两个高之间的容器能装最多的水,注意:容器不能倾斜。 解题思路: 从离得最远的两个数入手,最远的两数拥有最大的宽度,然后当前的高为头尾两数的最小值,用宽高求出当前水容量ans。接着先从左往右寻找第一个比当前高要高的左下标i,再从右往左找比当前

2017-02-26 19:02:04 157

原创 leetcode: 2. Add Two Numbers

题意: 将两个逆向链表表示的数加起来返回。 解题思路: 从低位到高位逐步把两个链表的数加起来赋给需要返回的链表,注意进位,每一步创建一个节点。当链表长度不一时,短的输入链表加完后再单独加上长的输入链表。 /** * Definition for singly-linked list. * struct ListNode { * int val; * List

2017-02-26 18:29:41 201

空空如也

空空如也

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

TA关注的人

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