- 博客(64)
- 收藏
- 关注
原创 证明NP问题(算法概论8.8)
Description 在精确的4SAT(EXACT 4SAT)问题中,输入为一组子句,每个子句都是恰好4个文字的析取,且每个变量最多在每个子句中出现一次。 目标是求它的满足赋值——如果该赋值存在。证明精确的4SAT是NP完全问题。Proof: 不难得到,书本中给出证明:3SAT问题是NP-完全的。 可知,对于问题A,B。若A是NP-完全的,则当我们将A归约到B时就可以证明得到B也是NP-完
2017-07-12 12:31:44
998
原创 LeetCode 322. Coin Change
322. Coin ChangeDescription You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amou
2017-06-12 01:34:47
459
原创 LeetCode 279. Perfect Squares
279. Perfect SquaresDescription Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 because 12
2017-06-12 01:28:24
441
原创 LeetCode 338. Counting Bits
338. Counting BitsDescription 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 arr
2017-06-12 01:21:43
404
原创 LeetCode 17. Letter Combinations of a Phone Number
17. Letter Combinations of a Phone NumberDescription Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the tele
2017-05-24 15:23:45
380
原创 LeetCode 3. Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating CharactersDescription Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which
2017-05-24 15:14:54
318
原创 LeetCode 28. Implement strStr()
28. Implement strStr()Description Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Analysis 这道题的意思就是实现一个strstr函数。 这个函数的返回值是
2017-05-24 15:06:38
289
原创 LeetCode 38. Count and Say
38. Count and SayDescription The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21.
2017-05-24 15:00:04
274
原创 LeetCode 14. Longest Common Prefix
14. Longest Common PrefixDescription Write a function to find the longest common prefix string amongst an array of strings.Analysis 题目的意思是求所给字符串组中公有的最大子前缀。 我的做法是首先假定建立一个变量index。 index来确定最大前缀在第一个字符串
2017-05-24 14:51:02
316
原创 LeetCode 456. 132 Pattern
456. 132 PatternDescription Given a sequence of n integers a1, a2, …, an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n num
2017-05-18 06:29:46
344
原创 LeetCode 402. Remove K Digits
402. Remove K DigitsDescription Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.Note: The length of num is le
2017-05-18 06:21:01
423
原创 LeetCode 394. Decode String
394. Decode StringDescription Given an encoded string, return it’s decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly
2017-05-18 06:12:05
595
原创 LeetCode 517. Super Washing Machines
517. Super Washing MachinesDescription You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.For each move, you could choose any m (1 ≤ m ≤ n) washi
2017-05-10 15:20:49
1469
原创 LeetCode 152. Maximum Product Subarray
152. Maximum Product SubarrayDescription Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the conti
2017-05-10 15:10:05
520
原创 LeetCode 343. Integer Break
343. Integer BreakDescription 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
2017-05-10 14:50:22
293
原创 LeetCode 120. Triangle
120. TriangleDescription Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle [
2017-05-10 14:39:09
299
原创 LeetCode 64. Minimum Path Sum
64. Minimum Path SumDescription 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.Note: You can only
2017-05-03 00:50:50
306
原创 LeetCode 91. Decode Ways
91. Decode WaysDescription A 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 digits, d
2017-05-03 00:43:22
304
原创 LeetCode 96. Unique Binary Search Trees
96. Unique Binary Search TreesDescription Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s.Analysi
2017-05-03 00:03:19
278
原创 LeetCode 303. Range Sum Query - Immutable
303. Range Sum Query - ImmutableDescription Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example: Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0,
2017-05-02 23:54:12
401
原创 LeetCode 62. Unique Paths
62. Unique PathsDescription 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
2017-05-01 02:43:48
247
原创 LeetCode 213. House Robber II
213. House Robber IIDescription After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at
2017-05-01 02:36:52
291
原创 LeetCode 198. House Robber
198. House RobberDescription You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each o
2017-05-01 02:32:32
245
原创 LeetCode 121. Best Time to Buy and Sell Stock
121. Best Time to Buy and Sell StockDescription Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i
2017-05-01 02:25:44
239
原创 LeetCode 70. Climbing Stairs
70. Climbing StairsDescription You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Analy
2017-05-01 02:18:49
335
原创 LeetCode 513. Find Bottom Left Tree Value
513. Find Bottom Left Tree ValueDescription Given a binary tree, find the leftmost value in the last row of the tree. Analysis 这道题的意思其实就是求树的最底层的最左边的节点。 一开始我也理解错了,以为是最底的一个左子树,后来才发现原来是求最底层的最左边的子树。 我
2017-04-22 16:41:13
421
原创 LeetCode 450. Delete Node in a BST
450. Delete Node in a BSTDescription Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.Basical
2017-04-22 15:23:59
318
原创 LeetCode 257. Binary Tree Paths
257. Binary Tree PathsDescription Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: All root-to-leaf paths are:[“1->2->5”, “1->3”]Analysis 这道题的求出所有从根
2017-04-22 15:12:42
336
原创 LeetCode 501. Find Mode in Binary Search Tree
Description Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node
2017-04-22 15:03:48
389
原创 LeetCode 543. Diameter of Binary Tree
Description Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path
2017-04-22 14:54:25
354
原创 LeetCode 19. Remove Nth Node From End of List
19. Remove Nth Node From End of ListDescription 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 removing
2017-04-13 00:06:23
304
原创 LeetCode 142. Linked List Cycle II
142. Linked List Cycle IIDescription Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it wit
2017-04-12 23:58:02
248
原创 LeetCode 141. Linked List Cycle
141. Linked List CycleDescription Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?Analysis 这道题目的意思就是判断链表中是否存在环。 我的做法是利用两个指针。其实觉得这道题需要用数学
2017-04-12 22:54:42
281
原创 LeetCode 92. Reverse Linked List II
* Reverse Linked List II*Description Reverse 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-04-12 22:48:59
236
原创 LeetCode 206. Reverse Linked List
Reverse Linked ListDescription Reverse a singly linked list.Analysis 从这道题这么简洁的表述中,不难看出这道题的意思就是给出一个链表,让我们把链表倒置。 我的做法就是新建一个链表指针pre,t。 每一次将pre变成当前指针的前一个指针,用t记录当前指针的下一个指针。 然后把当前指针的next变成pre。 然后更新pre成
2017-04-12 20:23:54
230
原创 LeetCode 234.Palindrome Linked List
Palindrome Linked ListDescription Given a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?Analysis 这道题的意思其实就是要我们判断链表是否为回文链表,而且对时间与空间复杂度都有要求
2017-04-12 20:13:46
260
原创 LeetCode 200. Number of Islands
200. Number of Islands* Description* Given 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 hori
2017-03-29 20:16:12
231
原创 LeetCode 102. Binary Tree Level Order Traversal
102. Binary Tree Level Order TraversalDescription Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree [
2017-03-29 20:10:10
229
原创 LeetCode 107. Binary Tree Level Order Traversal II
107. Binary Tree Level Order Traversal IIDescription Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).Fo
2017-03-29 20:00:34
265
原创 LeetCode 111. Minimum Depth of Binary Tree
111. Minimum Depth of Binary TreeDescription Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf no
2017-03-29 19:51:35
223
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人