Leetcode
文章平均质量分 50
xuweimdm
不拒细沙方能成其漠
展开
-
Leetcode63 Unique Paths II
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 r原创 2015-08-12 22:38:57 · 371 阅读 · 0 评论 -
Leetcode64 Minimum Path Sum
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. Note: You can only move eit原创 2015-08-12 23:09:36 · 543 阅读 · 0 评论 -
Leetcode62 Unique Paths
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 tryi原创 2015-08-12 19:35:09 · 465 阅读 · 0 评论 -
Leetcode37 Sudoku Solver
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原创 2015-07-29 14:25:59 · 389 阅读 · 0 评论 -
Leetcode36 Valid Sudoku
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 ‘.’. No原创 2015-07-29 11:42:13 · 373 阅读 · 0 评论 -
Leetcode61 Rotate List
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. Solution 利用两个指针定位原创 2015-08-10 13:37:47 · 356 阅读 · 0 评论 -
Leetcode60 Permutation Sequence
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):"1原创 2015-08-10 13:09:05 · 453 阅读 · 0 评论 -
Leetcode56 Merge Intervals
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]. Solution 将所有的interval按照起点进行排序,原创 2015-08-09 23:12:31 · 632 阅读 · 0 评论 -
Leetcode55 Jump Game
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.原创 2015-08-09 22:28:49 · 423 阅读 · 0 评论 -
Leetcode54 Spiral Matrix
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 ],原创 2015-08-09 21:57:49 · 389 阅读 · 0 评论 -
Leetcode57 Insert Interval
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 thei原创 2015-08-10 01:39:20 · 460 阅读 · 0 评论 -
Leetcode38 Count and Say
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. 2原创 2015-07-29 15:37:40 · 314 阅读 · 0 评论 -
Leetcode59 Spiral Matrix II
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,原创 2015-08-10 11:12:08 · 424 阅读 · 0 评论 -
Leetcode65 Plus One
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. Solution1pu原创 2015-08-12 23:36:18 · 540 阅读 · 0 评论 -
Leetcode 1
Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the原创 2015-07-23 22:40:05 · 372 阅读 · 0 评论 -
Leetcode44 Wildcard Matching
Wildcard Matching Implement wildcard pattern matching with support for ‘?’ and ‘*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).原创 2015-08-07 12:10:25 · 434 阅读 · 0 评论 -
Leetcode43 Multiply Strings
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. Solution1 最简单的方法就是完全原创 2015-08-06 15:12:26 · 710 阅读 · 0 评论 -
Leetcode40 Combination Sum II
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原创 2015-08-05 16:22:47 · 428 阅读 · 0 评论 -
Leetcode42 Trapping Rain Water
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原创 2015-08-06 10:18:12 · 354 阅读 · 0 评论 -
Leetcode41 First Missing Positive
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 ru原创 2015-08-05 17:59:26 · 479 阅读 · 0 评论 -
Leetcode 11 Container With Most Water
Container With Most Water Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i,原创 2015-07-25 10:23:45 · 519 阅读 · 0 评论 -
Leetcode 6 ZigZag Conversion
ZigZag Conversion The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A原创 2015-07-24 23:41:54 · 516 阅读 · 0 评论 -
Leetcode 5 Longest Palindromic Substring
Longest Palindromic Substring Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic subst原创 2015-07-24 22:20:10 · 419 阅读 · 0 评论 -
Leetcode 9 Palindrome Number
Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer t原创 2015-07-25 01:25:20 · 491 阅读 · 0 评论 -
Leetcode 7 Reverse Integer
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Solution1 像这种有可能会超出数据类型范围的情况,一般有两种比较好的解决办法:一种是用一个可以表示更大的数据类型,比如这里用long类型;另一种是用字符串去模拟大原创 2015-07-25 00:41:37 · 579 阅读 · 0 评论 -
Leetcode39 Combination Sum
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原创 2015-07-30 11:30:29 · 339 阅读 · 0 评论 -
Leetcode 2
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 re原创 2015-07-23 23:53:28 · 869 阅读 · 0 评论 -
Leetcode 3 Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for原创 2015-07-24 09:49:52 · 560 阅读 · 0 评论 -
Leetcode58 Length of Last Word
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原创 2015-08-10 10:29:14 · 434 阅读 · 0 评论 -
Leetcode32 Longest Valid Parentheses
Longest Valid Parentheses Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring. For “(()”, the longest valid parent原创 2015-07-28 01:42:58 · 306 阅读 · 0 评论 -
Leetcode53 Maximum Subarray
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原创 2015-08-09 17:18:49 · 434 阅读 · 0 评论 -
Leetcode 21 Merge Two Sorted Lists
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. Solution1 这道题思路特别清晰,就是分别从两条链表的头部开始原创 2015-07-26 23:34:03 · 320 阅读 · 0 评论 -
Leetcode 22 Generate Parentheses
Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: “((()))”, “(()())原创 2015-07-27 01:37:11 · 415 阅读 · 0 评论 -
Leetcode 27 Remove Element
Remove Element Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn’t matter what you leave beyond th原创 2015-07-27 12:48:12 · 273 阅读 · 0 评论 -
Leetcode 24 Swap Nodes in Pairs
Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should原创 2015-07-27 12:23:17 · 318 阅读 · 0 评论 -
Leetcode 23 Merge k Sorted Lists
Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Solution1 将链表利用二分法两两进行合并。代码如下: public class Solution { public ListNode merg原创 2015-07-27 11:33:23 · 352 阅读 · 0 评论 -
Leetcode 19 Remove Nth Node From End of List
Remove Nth Node From End of List 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 the s原创 2015-07-26 11:54:21 · 279 阅读 · 0 评论 -
Leetcode 13 Roman to Integer
Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. Solution 基本思路是将字符串中的每一个字母代表的数都加起来,但是有一种情况例外,就是当较小的单位出现在较大单位的左边时,表示要减去这个原创 2015-07-25 12:09:57 · 502 阅读 · 0 评论 -
Leetcode 12 Integer to Roman
Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. Solution 这道题如果针对每一位用if或者switch来判断,则要枚举的情况太多,所以最简洁的方法便是将每一位的所有情况先枚举出来,然后原创 2015-07-25 11:11:30 · 544 阅读 · 0 评论 -
Leetcode 14 Longest Common Prefix
Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. Solution1 最简单的方法就是遍历去比较每一个字符串。第一个字符串与第二个字符串进行比较得到一个前缀,然后拿这个前缀去跟第三个字符串去进行比较,以此类推。代码如下: publ原创 2015-07-25 13:01:49 · 542 阅读 · 0 评论