
leetcode
文章平均质量分 68
iyupaopao
天行健,君子以自强不息。地势坤,君子以厚德载物!
展开
-
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 · 329 阅读 · 0 评论 -
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 · 225 阅读 · 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 · 268 阅读 · 0 评论 -
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 · 242 阅读 · 0 评论 -
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 · 378 阅读 · 0 评论 -
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 · 458 阅读 · 0 评论 -
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 · 171 阅读 · 0 评论 -
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 · 178 阅读 · 0 评论 -
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 · 412 阅读 · 0 评论 -
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 · 253 阅读 · 0 评论 -
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 · 211 阅读 · 0 评论 -
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 · 175 阅读 · 0 评论 -
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 · 344 阅读 · 0 评论 -
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 · 197 阅读 · 0 评论 -
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 · 324 阅读 · 0 评论 -
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 · 235 阅读 · 0 评论 -
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 · 216 阅读 · 0 评论 -
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 · 374 阅读 · 0 评论 -
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 · 283 阅读 · 0 评论 -
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 · 417 阅读 · 0 评论 -
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 · 335 阅读 · 0 评论 -
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 · 179 阅读 · 0 评论 -
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 · 289 阅读 · 0 评论 -
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 · 200 阅读 · 0 评论 -
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 · 203 阅读 · 0 评论 -
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 · 319 阅读 · 0 评论 -
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 · 234 阅读 · 0 评论 -
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 · 220 阅读 · 0 评论 -
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 · 244 阅读 · 0 评论 -
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 · 237 阅读 · 0 评论 -
LeetCode进阶之路(Valid Parentheses)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2016-07-21 23:21:20 · 193 阅读 · 0 评论 -
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 · 220 阅读 · 0 评论 -
LeetCode进阶之路(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)).Example 1:nums1原创 2016-07-06 00:10:59 · 168 阅读 · 0 评论 -
LeetCode进阶之路(3Sum Closest)
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly原创 2016-07-15 23:53:13 · 252 阅读 · 1 评论 -
LeetCode进阶之路(3Sum)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain原创 2016-07-14 23:57:48 · 355 阅读 · 0 评论 -
LeetCode进阶之路(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.题目:两个有序的链表组合成一个有序的新链表。思路:因为是有序的,所以把每个节点都取出来放到一个list原创 2016-07-24 23:50:31 · 183 阅读 · 0 评论 -
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 answer is "原创 2016-07-05 00:27:07 · 159 阅读 · 0 评论 -
LeetCode进阶之路(Merge k Sorted Lists)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目:把k个有序的链表合并成一个新的链表。思路:采用合并两个链表的方法,把K个链表的值都取出来放到list里面,排序后创建新的链表。public class Solution {原创 2016-07-25 23:39:51 · 192 阅读 · 0 评论 -
LeetCode进阶之路(Longest Common Prefix)
Write a function to find the longest common prefix string amongst an array of strings.题目:在一个字符串数组中,求最长的初始串。思路:先比较前两个,得到最长初始子串,之后拿这个子串去和第三个相比较,以此类推;public String longestCommonPrefix(String[] s) {原创 2016-07-14 22:53:16 · 225 阅读 · 0 评论 -
LeetCode进阶之路(Add Two Numbers)
题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as原创 2016-07-03 23:25:35 · 317 阅读 · 0 评论