
LeetCode
文章平均质量分 70
CaptainStanley
这个作者很懒,什么都没留下…
展开
-
LeetCode OJ算法题(八十):Remove Duplicates from Sorted Array II
题目:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is no原创 2014-08-27 14:37:24 · 397 阅读 · 0 评论 -
LeetCode OJ算法题(五十五):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].解法:timu原创 2014-08-08 21:12:14 · 483 阅读 · 0 评论 -
LeetCode OJ算法题(五十九):Permutation Sequence
题目:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""21原创 2014-08-08 21:39:05 · 458 阅读 · 0 评论 -
LeetCode OJ算法题(五十):N Queens
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens原创 2014-08-07 20:39:30 · 455 阅读 · 0 评论 -
LeetCode OJ算法题(五十七):Length of Last Word
题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note:原创 2014-08-08 21:29:03 · 346 阅读 · 0 评论 -
LeetCode OJ算法题(五十八):Spiral Matrix II
题目:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9原创 2014-08-08 21:31:26 · 494 阅读 · 0 评论 -
LeetCode OJ算法题(六十一):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 r原创 2014-08-26 21:27:15 · 446 阅读 · 0 评论 -
LeetCode OJ算法题(六十四):Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.解法:实际上就是归并排序的lian原创 2014-08-26 21:51:37 · 394 阅读 · 0 评论 -
LeetCode OJ算法题(六十五):Add Binary
题目:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".解法:原创 2014-08-26 22:01:57 · 434 阅读 · 0 评论 -
LeetCode OJ算法题(五十四):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.De原创 2014-08-07 21:06:09 · 433 阅读 · 0 评论 -
LeetCode OJ算法题(五十三):Spiral Matrix
题目:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9原创 2014-08-07 20:59:03 · 416 阅读 · 0 评论 -
LeetCode OJ算法题(四十八):Anagrams
题目:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.解法:所谓的anagrams是指原创 2014-08-06 20:09:51 · 416 阅读 · 0 评论 -
LeetCode OJ算法题(四十七):Rotate Image
题目:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?解法:shunshiji原创 2014-08-06 15:30:20 · 433 阅读 · 0 评论 -
LeetCode OJ算法题(四十九):Pow(x, n)
题目:Implement pow(x, n).解法:题目要求shi原创 2014-08-06 20:20:08 · 401 阅读 · 0 评论 -
LeetCode OJ算法题(四十六):Permutation II
题目:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and原创 2014-08-06 14:39:47 · 509 阅读 · 0 评论 -
LeetCode OJ算法题(四十一):Trapping Rain Water
题目:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3原创 2014-08-01 12:47:00 · 457 阅读 · 0 评论 -
LeetCode OJ算法题(四十五):Permutations
题目:Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].解法:要原创 2014-08-06 14:34:54 · 394 阅读 · 0 评论 -
LeetCode OJ算法题(五十一):N Queens II
题目:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.解法:jiefa原创 2014-08-07 20:48:09 · 421 阅读 · 0 评论 -
LeetCode OJ算法题(五十二):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 subarra原创 2014-08-07 20:53:01 · 423 阅读 · 0 评论 -
LeetCode OJ算法题(六十七):Plus One
题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.解法:原创 2014-08-26 22:26:59 · 480 阅读 · 0 评论 -
LeetCode OJ算法题(六十):Rotate List
题目:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.解法:原创 2014-08-26 21:17:31 · 514 阅读 · 0 评论 -
LeetCode OJ算法题(五十六):Insert Interval
题目:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start ti原创 2014-08-08 21:20:57 · 461 阅读 · 0 评论 -
LeetCode OJ算法题(七十六):Minimum Window Substring
题目:Given 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 = "ABC"Minimum windo原创 2014-08-27 14:05:54 · 493 阅读 · 0 评论 -
LeetCode OJ算法题(八十一):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?Write a function to determine if a given target原创 2014-08-27 14:43:16 · 418 阅读 · 0 评论 -
LeetCode OJ算法题(八十三):Remove Duplicates from Sorted List II
题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Gi原创 2014-08-27 15:05:45 · 461 阅读 · 0 评论 -
LeetCode OJ算法题(六十八):Text Justification
题目:Given 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 in a greedy approac原创 2014-08-27 12:27:37 · 626 阅读 · 0 评论 -
LeetCode OJ算法题(七十一):Simplify Path
题目:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:原创 2014-08-27 12:51:12 · 673 阅读 · 0 评论 -
LeetCode OJ算法题(七十四):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 intege原创 2014-08-27 13:49:44 · 471 阅读 · 0 评论 -
LeetCode OJ算法题(七十八):Subsets
题目:Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.原创 2014-08-27 14:22:54 · 488 阅读 · 0 评论 -
LeetCode OJ算法题(七十三):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原创 2014-08-27 13:34:27 · 640 阅读 · 0 评论 -
LeetCode OJ算法题(八十二):Remove Duplicates from Sorted List
题目: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->1->2->3->3, return 1->2->3.解法:Remove Dupl原创 2014-08-27 14:58:55 · 411 阅读 · 0 评论 -
LeetCode OJ算法题(六十三):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.解法:原创 2014-08-26 21:46:36 · 461 阅读 · 0 评论 -
LeetCode OJ算法题(六十二):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原创 2014-08-26 21:36:03 · 410 阅读 · 0 评论 -
LeetCode OJ算法题(六十六):Valid Number
题目:Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to b原创 2014-08-26 22:11:03 · 708 阅读 · 0 评论 -
LeetCode OJ算法题(六十九):Sqrt(x)
题目:mplement int sqrt(int x).Compute and return the square root of x.解法:和前面的不用che原创 2014-08-27 12:39:32 · 458 阅读 · 0 评论 -
LeetCode OJ算法题(七十):Climbing Stairs
题目: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?解法:采用DP算法,找到递推关系式。原创 2014-08-27 12:47:56 · 494 阅读 · 0 评论 -
LeetCode OJ算法题(七十二):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 o原创 2014-08-27 12:58:56 · 839 阅读 · 0 评论 -
LeetCode OJ算法题(七十五):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原创 2014-08-27 13:56:50 · 520 阅读 · 0 评论 -
LeetCode OJ算法题(七十七):Combinations
题目:Given 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], [2,3], [1,2], [1,3],原创 2014-08-27 14:19:30 · 489 阅读 · 0 评论 -
LeetCode OJ算法题(十):Regular Expression Matching
题目:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire原创 2014-07-15 14:06:03 · 795 阅读 · 0 评论