自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 欢迎使用优快云-markdown编辑器

吝啬SAT问题 - NPC问题证明吝啬SAT问题是这样描述的:给定一组子句(每个子句都是其中文字的析取)和整数k,求一个最多有k个变量为true的满足赋值——如果该赋值存在。证明吝啬SAT是NP-完全问题.证明: 首先我们知道SAT是NP完全问题, 然后SAT的问题本质是, 一共n个变量, 最多n个变量都取true也能满足.因此可以想到把吝啬SAT问题规约到SAT问题上: 取n=k, 那么吝啬SA

2017-06-17 15:58:13 254

原创 [算法作业-动态规划][LeetCode] 97. Interleaving String

[算法作业-动态规划][LeetCode] 97. Interleaving StringGiven s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, retur

2017-04-10 11:07:54 344

原创 [算法作业][LeetCode] 133. Clone Graph

[算法作业][LeetCode] 133. Clone GraphClone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization: Nodes are labeled uniquely.We use #

2017-03-19 23:07:33 272

原创 [LeetCode] 115. Distinct Subsequences

[LeetCode] 115. Distinct SubsequencesGiven 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 str

2017-03-03 13:45:10 255

原创 [LeetCode] 99. Recover Binary Search Tree

[LeetCode] 99. Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.一棵二叉搜索树,有两个节点换过来了,需要找出这两个节点,换回来。我们发现,一棵完好的BST,

2017-03-03 13:34:37 229

原创 [算法作业][LeetCode] 50. Pow(x, n) -- 分治法

[算法作业][LeetCode] 50. Pow(x, n) – 分治法Implement pow(x, n).对于xnx^n,可以通过分治的方法,设n=2kn = 2^k: xn=xn/2∗xn/2∗xn%2x^n = x^{n/2} * x^{n/2} * x^{n\%2} xn/2=xn/4∗xn/4∗xn/2%2x^{n/2} = x^{n/4} * x^{n/4} * x^{n/

2017-03-03 13:23:31 444

原创 [LeetCode] 97. Interleaving String

[LeetCode] 97. Interleaving StringGiven s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, return true. Wh

2017-02-27 23:47:54 365

原创 [LeetCode] 98. Validate Binary Search Tree

[LeetCode] 98. Validate Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with

2017-02-27 23:44:42 254

原创 [LeetCode] 95. Unique Binary Search Trees II & I

[LeetCode] 95. Unique Binary Search Trees II & IGiven an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should ret

2017-02-27 00:10:05 233

原创 94. Binary Tree Inorder Traversal

[LeetCode] 94. Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 retur

2017-02-27 00:04:59 229

原创 [LeetCode] 93. Restore IP Addresses

[LeetCode] 93. Restore IP AddressesGiven a string containing only digits, restore it by returning all possible valid IP address combinations.For example: Given “25525511135”,return [“255.255.11.135”,

2017-02-27 00:01:17 212

原创 [LeetCode] 92. Reverse Linked List II

[LeetCode] 92. Reverse Linked List IIReverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:

2017-02-26 23:55:59 205

原创 [LeetCode] 91. Decode Ways

[LeetCode] 91. Decode WaysA message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing dig

2017-02-26 23:46:48 227

原创 [LeetCode] 90. Subsets II

[LeetCode] 90. 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-02-26 00:50:11 207

原创 [LeetCode] 89. Gray Code

[LeetCode] 89. Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, pri

2017-02-26 00:47:27 220

原创 [LeetCode] 88. Merge Sorted Array

[LeetCode] 88. Merge Sorted ArrayGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or e

2017-02-26 00:37:31 218

原创 [LeetCode] 87. Scramble String

[LeetCode] 87. Scramble StringGiven 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”:

2017-02-26 00:28:53 244

原创 [LeetCode] 86. Partition List

[LeetCode] 86. Partition ListGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order

2017-02-26 00:23:31 236

原创 [LeetCode] 85. Maximal Rectangle

[LeetCode] 85. Maximal RectangleGiven a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.For example, given the following matrix: 1 0 1 0 0

2017-02-25 02:13:46 240

原创 [LeetCode] 84. Largest Rectangle in Histogram

[LeetCode] 84. Largest Rectangle in HistogramGiven n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.

2017-02-25 01:41:12 363

原创 83 & 84. Remove Duplicates from Sorted List I & II

[LeetCode] 83 & 84. Remove Duplicates from Sorted List I & II Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1

2017-02-25 01:38:54 197

原创 [LeetCode] 81. Search in Rotated Sorted Array II

[LeetCode] 81. Search in Rotated Sorted Array II Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppos

2017-02-25 01:31:34 192

原创 80. Remove Duplicates from Sorted Array II

[LeetCode] 80. Remove Duplicates from Sorted Array IIFollow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function

2017-02-23 23:59:25 200

原创 79. Word Search

[LeetCode] 79. Word SearchGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horiz

2017-02-23 23:53:21 205

原创 [LeetCode] 78. Subsets

[LeetCode] 78. 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-02-23 23:41:06 220

原创 [LeetCode] 77. Combinations

[LeetCode] 77. CombinationsGiven two integers n and k, return all possible combinations of k numbers out of 1 … n.For example, If n = 4 and k = 2, a solution is: [   [2,4],   [3,4],

2017-02-23 23:37:46 265

原创 [LeetCode] 76. Minimum Window Substring

[LeetCode] 76. Minimum Window SubstringGiven 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 =

2017-02-23 22:01:27 309

原创 [LeetCode] 75. Sort Colors

[LeetCode] 75. Sort ColorsGiven 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 w

2017-02-23 01:50:36 216

原创 [LeetCode] 74. Search a 2D Matrix

[LeetCode] 74. Search a 2D MatrixWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.

2017-02-23 01:42:29 197

原创 [LeetCode] 73. Set Matrix Zeroes

[LeetCode] 73. Set Matrix ZeroesGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up: Did you use extra space? A straight forward solution using O(mn

2017-02-23 01:31:52 252

原创 [LeetCode] 72. Edit Distance

[LeetCode] 72. Edit DistanceGiven 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 operatio

2017-02-23 01:18:12 230

原创 [LeetCode] 71. Simplify Path

[LeetCode] 71. Simplify PathGiven an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c”Corner Cases: Did you consider the ca

2017-02-22 01:00:08 187

原创 [LeetCode] 28. Implement strStr()

[LeetCode] 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.实现strStr(h, n)函数,如果在h中能找到n的完全匹配字符串,则返回对应的第一个

2017-02-21 23:16:52 260

原创 [LeetCode] 68. Text Justification

[LeetCode] 68. Text JustificationGiven an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words

2017-02-21 21:52:13 223

原创 [LeetCode]69. Sqrt(x)

[LeetCode]69. Sqrt(x)Implement int sqrt(int x). Compute and return the square root of x.实现sqrt(x)函数。思想:二分查找m,使得m*m最接近x。注意m*m会超过int的范围。class Solution { public: int mySqrt(int x) { int l = 0

2017-02-21 21:49:18 250

空空如也

空空如也

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

TA关注的人

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