- 博客(32)
- 收藏
- 关注
原创 Leetcode解题报告:279. Perfect Squares
题意: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 = 4 + 4 + 4; gi
2017-01-07 20:10:25
354
原创 算法概论习题:8.14NP-完全问题的证明
8.14问题描述: 证明如下问题是NP-完全的:给定一个无向图G(V,E)和整数k,求G的一个规模为K的团以及一个规模为K的独立集,假设二者都是存在的。(1)可以将3SAT问题归约到求无向图G的规模为K的团。 考虑一个有K个子句的3SAT实例,每个字句包含不超过3个文字。可以构造一个无向图G,每个属于3SAT公式中的文字对应G中的一个节点。在3SAT公式中属于一个子句的结点在图G
2016-12-24 01:53:07
1335
原创 leetcode解题报告:62. 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 reach the
2016-11-27 21:38:48
336
原创 Leetcode解题报告:207. Course Schedule
题目: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 expr
2016-11-26 23:47:38
489
原创 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,0
2016-11-23 15:48:35
282
原创 leetcode解题报告:53. 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,2,1]
2016-11-22 00:41:10
302
原创 leetcode解题报告:45. Jump Game II
题意:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your
2016-11-14 21:06:11
315
原创 Leetcode解题报告:406. 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 fro
2016-11-14 19:45:37
467
原创 leetcode解题报告:213. House Robber II
题意: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 this place are arranged
2016-10-31 16:01:20
250
原创 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 =
2016-10-22 19:00:23
550
原创 leetcode解题报告:56. Merge Intervals
题意:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].难度:Hard解题思路:需要把有重复区间的所有区间合并成1个,不与其他区间重复
2016-10-10 17:42:41
242
原创 leetcode解题报告:238. Product of Array Except Self
题意:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division
2016-10-06 01:58:28
252
原创 leetcode解题报告:75. Sort Colors
题意:Given 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 will use the intege
2016-10-04 23:52:06
278
原创 Leetcode解题报告:94. Binary Tree Inorder Traversal
题意:Given a binary tree, return the inorder traversal of its nodes' values.难度:Medium解题思路:简单的中序遍历问题,当根节点存在左子树的时候,先遍历左子树,当返回到跟结点的时候,把根节点值加入答案数组,再遍历右子树(如果存在的话)。时间复杂度O(n),如果当前结点没有左右子树,当前值也要加入答案数组。/
2016-10-04 00:52:37
293
原创 leetcode解题报告:135. Candy
题意:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least
2016-10-02 19:10:31
474
原创 Leetcode解题报告:73. Set Matrix Zeroes
题意:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution
2016-10-02 15:43:34
308
原创 Leetcode解题报告:48. Rotate Image
题意:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).难度:Medium解题思路一: 顺时针旋转90°,其实就是第i列倒序变成第 i行,很容易想到先把原矩阵复制到一个temp矩阵中,然后再遍历一次,把temp中的列按倒序
2016-10-01 14:46:31
235
原创 leetcode解题报告:104. Maximum Depth of Binary Tree
题意:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.难度:Easy解题思路: 这是一道简单的深
2016-09-28 00:50:15
379
原创 leetcode解题报告:129. Sum Root to Leaf Numbers
题意:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find t
2016-09-25 15:00:58
307
原创 Leetcode解题报告:Search Insert Position
题目大意:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the a
2016-09-21 00:01:51
266
原创 Leetcode解题报告:4. Median of Two Sorted Arrays
题意:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).难度:Hard解题
2016-09-20 01:48:28
503
原创 Leetcode解题报告:74. Search a 2D Matrix
题目大意:Write 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.The first inte
2016-09-14 11:45:52
249
原创 Leetcode解题报告:268. Missing Number
题意:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algori
2016-09-14 11:01:56
303
原创 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,
2016-09-14 00:24:10
296
原创 leetcode解题报告:240. Search a 2D Matrix II
题目大意:Write 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 in ascending from left to right.I
2016-09-12 19:25:51
533
原创 Leetcode解题报告:169. Majority Element
题意:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority e
2016-09-11 00:48:31
210
原创 Leetcode题解:127. Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length ofshortest transformation sequence from beginWordto endWord, such that:Only one letter can be changed at a
2016-09-07 02:12:44
338
原创 Leetcode题解:55. Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i
2016-09-06 21:58:30
241
原创 leetcode题解:Number of Islands
题号200题意: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 horizontally or vertically.
2016-09-06 14:16:43
404
原创 Leetcode题解:First Unique Character in a String
题目:Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.难度:Easy解题思路:比较容易想到的方法是用哈希表,先遍历一遍字符串,因为只有26个小写字母,开一个大小为26的数组a,对每一个扫到的字母,a[s[i]-
2016-09-06 01:17:40
291
原创 Leetcode题解: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
2016-09-06 00:57:08
479
原创 Leetcode题解:Pow(x, n)
题目描述:Implement pow(x, n). 难度 Medium解题思路:利用分治法(Divide and Conquer),对n进行划分,如果n为偶数,那么可以先求出x^(n/2) ,得到结果后对其求平方,即可得到x^n=x^(n/2) * x^(n/2). 如果n为奇数,则x^n=x^((n-1)/2)*x^((n-1)/2)*x. 这样一来一个规
2016-09-05 22:53:25
498
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人