- 博客(20)
- 收藏
- 关注
原创 《算法概论》习题8.12题解
问题: 8.12 k-生成树问题是这样的: 输入:无向图G=(V,E) 输出:G的一个生成树,其中所有节点度数都不超过k——如果该树存在。 请证明对任意k>=2: (a)k-生成树问题是一个搜索问题。 (b)k-生成树问题是NP-完全的。 证明: (a)对于实例I,其任意一个解S,遍历S的每个结点,检查其度数是否不超过k,这是多项式时间内可做到的;此外检测S是否为一棵树也能在多项式
2017-01-12 20:35:57 327
原创 《算法概论》习题8.3 吝啬SAT
问题: 8.3 吝啬SAT问题是这样的:给定一组子句(每个子句都是其中文字的析取)和整数k,求一个最多有k个变量为true的满足赋值——如果该赋值存在。证明吝啬SAT是NP-完全问题 解: 我们考虑将SAT规约至吝啬SAT: 对于任意一个SAT问题,设其有n个变量,则该SAT问题的满足赋值中最多有n个变量赋值为true,这相当于一个输入为(S,n)的吝啬SAT问题,所以一个SAT实
2017-01-12 20:13:05 566
原创 ZigZag Conversion
题目 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
2017-01-09 12:28:33 387
转载 Longest Palindromic Substring
题目 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answ
2016-12-12 18:48:50 1200 1
原创 Two Sum
题目 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. Example: Give
2016-12-02 22:14:57 320
转载 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 ans
2016-12-02 20:04:19 278
转载 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
2016-11-16 14:35:09 257
转载 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,00
2016-11-06 16:50:58 214
原创 Queue Reconstruction by Height
题目 Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in fr
2016-11-06 16:16:24 381
转载 Unique Paths II
题目 Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively
2016-10-31 00:13:17 183
转载 Unique Paths
题目 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to re
2016-10-30 23:48:18 180
转载 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,
2016-10-30 23:22:01 176
转载 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
2016-10-15 00:41:35 195
转载 Count Numbers with Unique Digits
题目 Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x [11,2
2016-10-15 00:00:34 216
原创 Course Schedule II
题目 There 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 course 1, which is expre
2016-09-25 15:57:57 201
转载 Minimum Path Sum
题目 Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. 分析 乍看到这个题目我还以为是个图的最小路径问题,受到先入为
2016-09-25 15:02:04 227
原创 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:
2016-09-24 16:00:29 454
原创 Balanced Binary Tree
题目 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node nev
2016-09-11 20:05:19 331
原创 Different Ways to Add Parentheses
题目 Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *. Example
2016-09-11 00:50:24 229
原创 一个简单的linked list问题
题目: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as
2016-09-04 17:21:32 321
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人