- 博客(73)
- 资源 (5)
- 收藏
- 关注
原创 LeetCode进阶之路(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 be ambiguo
2016-09-22 23:03:26 304
原创 LeetCode进阶之路(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.题目:还是寻找路径,不过这次是寻找最短的路径。思路:还是使用动态规划。public
2016-09-22 22:59:05 357
原创 LeetCode进阶之路(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 in the
2016-09-22 22:52:54 268
原创 LeetCode进阶之路(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-09-13 23:32:53 299
原创 LeetCode进阶之路(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.题目:倒着数k个node,从那开始到结尾和之前那部分对调,那个例子
2016-08-28 21:57:24 362
原创 LeetCode进阶之路(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""213""231""3
2016-08-27 22:19:57 431
原创 LeetCode进阶之路(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, 4 ], [
2016-08-26 21:57:21 401
原创 LeetCode进阶之路(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: A word is
2016-08-23 21:42:38 189
原创 LeetCode进阶之路(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 times.E
2016-08-23 21:30:01 194
原创 LeetCode进阶之路(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].题目:有很多个区间,把有重叠的区间合并。思路:先按照start排序,之后在比较前一个和后一个的e
2016-08-22 22:42:37 233
原创 LeetCode进阶之路(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 ]]
2016-08-21 15:39:16 226
原创 LeetCode进阶之路(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-08-19 22:27:42 226
原创 LeetCode进阶之路(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 puzzle.
2016-08-19 22:22:39 313
原创 LeetCode进阶之路(Pow(x, n))
Implement pow(x, n).题目:求x^n次方。思路:用递归,但是自己写的时候没考虑仔细,出现了栈溢出的错误(java.lang.StackOverflowError) public double myPow(double x, int n) { if(n == 1){ return x; }
2016-08-16 21:55:20 391
原创 LeetCode进阶之路(Group Anagrams)
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note: Al
2016-08-16 21:46:13 245
原创 LeetCode进阶之路(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?题目:n x n的数组反转90度。思路:举个例子观察一下就行了。第一行变成最后一列,第二行变成倒数
2016-08-16 21:36:08 200
原创 LeetCode进阶之路(Permutations 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], [2,1
2016-08-14 17:10:09 313
原创 LeetCode进阶之路(Permutations)
Given a collection of distinct 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], [3,2,1
2016-08-14 17:04:15 203
原创 LeetCode进阶之路( 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 goal i
2016-08-12 21:44:05 168
原创 LeetCode进阶之路( 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-08-11 21:29:02 282
原创 LeetCode进阶之路( 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,2,1,2,1]
2016-08-10 22:04:52 212
原创 LeetCode进阶之路( Wildcard Matching)
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t
2016-08-09 23:09:58 221
原创 LeetCode进阶之路( Multiply Strings)
Given two numbers represented as strings, return multiplication of the numbers as a string.Note:The numbers can be arbitrarily large and are non-negative.Converting the input string to integ
2016-08-08 22:48:24 207
原创 LeetCode进阶之路( First Missing Positive)
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant
2016-08-07 22:00:17 204 5
原创 LeetCode进阶之路( Combination Sum II)
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina
2016-08-06 22:49:17 252
原创 LeetCode进阶之路(Combination Sum)
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb
2016-08-06 22:28:43 225
原创 LeetCode进阶之路( Count and Say)
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.21 is read off as
2016-08-04 22:13:33 188
原创 回溯算法
引言:寻找问题的解的一种可靠的方法是首先列出所有候选解,然后依次检查每一个,在检查完所有或部分候选解后,即可找到所需要的解。理论上,当候选解数量有限并且通过检查所有或部分候选解能够得到所需解时,上述方法是可行的。不过,在实际应用中,很少使用这种方法,因为候选解的数量通常都非常大(比如指数级,甚至是大数阶乘),即便采用最快的计算机也只能解决规模很小的问题。对候选解进行系统检查的方法有多种,其中回
2016-08-03 22:43:16 375
原创 LeetCode进阶之路( Sudoku Solver)
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku
2016-08-02 22:41:07 187
原创 LeetCode进阶之路(Valid Sudoku)
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille
2016-08-02 22:36:30 162
原创 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 array.
2016-08-02 22:26:00 169
原创 LeetCode进阶之路( Search for a Range)
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found
2016-08-02 00:15:26 164
原创 LeetCode进阶之路(Submission Details)
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur
2016-08-01 22:12:36 328
原创 排序算法
昨天刷leetcode用到了排序算法,简单整理了一下冒泡排序和快速排序,今天抽时间把其他的几个排序也整理一下。1.插入排序—直接插入排序(Straight Insertion Sort)将元素插入到一个已经排好序的数组中,形成一个新的有序数列,重复这个动作,直到完成。重点:以第一个为初始元素,往后遍历,如果比前一个大,就接着往后遍历,否则就是寻找到目标点。举个例子:{1,2,4
2016-07-31 15:39:58 164
原创 LeetCode进阶之路(Next Permutation)
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible
2016-07-30 23:23:05 264
原创 LeetCode进阶之路(Substring with Concatenation of All Words)
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and
2016-07-30 23:05:05 209
原创 LeetCode进阶之路(Divide Two Integers)
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题目:两个数相除,不能用除法、乘法。思路:第一个反映应该是用位移,a*2^b = apublic int divide(int dividend,
2016-07-28 22:11:27 257
原创 LeetCode进阶之路(Implement strStr())
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题目:这题目是要找出第一个相同串的位置。思路:相当简单,遍历字符串,根据第二个串的长度找相同长的串比较就行,找到第一个即结束遍历
2016-07-28 21:58:35 159
原创 LeetCode进阶之路(Remove Element)
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.
2016-07-28 21:55:05 165
原创 LeetCode进阶之路(Remove Duplicates from Sorted Array)
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with
2016-07-28 21:50:45 159
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人