LeetCode
文章平均质量分 85
江枫abalone
这个作者很懒,什么都没留下…
展开
-
LeetCode -- Longest Palindromic Substring
链接:http://leetcode.com/onlinejudge#question_5原题: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 uniqu原创 2013-09-05 15:21:23 · 573 阅读 · 0 评论 -
LeetCode —— Best Time to Buy and Sell Stock III
链接:http://leetcode.com/onlinejudge#question_123原题:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You原创 2013-08-06 19:43:56 · 707 阅读 · 0 评论 -
LeetCode —— Anagrams
链接:http://leetcode.com/onlinejudge#question_49原题:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路:什么是anagram?一个字符串,把它的字母任原创 2013-08-06 17:25:02 · 816 阅读 · 0 评论 -
LeetCode——Unique Paths II
链接:http://leetcode.com/onlinejudge#question_63原题: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原创 2013-08-03 16:50:42 · 562 阅读 · 0 评论 -
LeetCode —— Scramble String
链接:http://leetcode.com/onlinejudge#question_87原题:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible repr原创 2013-07-27 15:18:11 · 848 阅读 · 0 评论 -
LeetCode——Generate Parentheses
链接:http://leetcode.com/onlinejudge#question_22题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution s原创 2013-06-29 14:11:41 · 652 阅读 · 0 评论 -
LeetCode —— Sort Colors
链接:http://leetcode.com/onlinejudge#question_75原题: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 orde原创 2013-05-23 20:09:10 · 667 阅读 · 0 评论 -
LeetCode——Word Ladder II
链接:http://leetcode.com/onlinejudge#question_126原题:Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one原创 2013-05-04 20:47:38 · 8707 阅读 · 8 评论 -
LeetCode——Surrounded Regions
链接:http://leetcode.com/onlinejudge#question_130原题:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's i原创 2013-05-04 16:47:33 · 832 阅读 · 0 评论 -
LeetCode —— Interleaving String
链接:http://leetcode.com/onlinejudge#question_97原题:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3原创 2013-04-16 21:32:08 · 584 阅读 · 0 评论 -
LeetCode —— Reverse Linked List II
链接:http://leetcode.com/onlinejudge#question_92原题:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,r原创 2013-04-19 22:57:48 · 560 阅读 · 0 评论 -
LeetCode——Divide Two Integers
链接:http://leetcode.com/onlinejudge#question_29原题:Divide two integers without using multiplication, division and mod operator.思路:把除数向左移位,然后去减被除数;只要小心INT_MIN就可以了,因为abs(INT_MIN)如果不转为long long的话,返回的原创 2013-08-25 19:38:53 · 633 阅读 · 0 评论 -
LeetCode —— Median of Two Sorted Arrays
链接:http://leetcode.com/onlinejudge#question_4原题:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should b原创 2013-09-05 19:30:00 · 758 阅读 · 0 评论 -
LeetCode —— Largest Rectangle in Histogram
链接:http://leetcode.com/onlinejudge#question_84原题:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in原创 2013-07-27 16:50:00 · 645 阅读 · 0 评论 -
LeetCode —— Regular Expression Matching
链接:http://leetcode.com/onlinejudge#question_10原题:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding原创 2013-09-03 11:09:29 · 1084 阅读 · 0 评论 -
LeetCode —— Trapping Rain Water
链接:http://leetcode.com/onlinejudge#question_42原题: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 r原创 2013-09-03 14:02:12 · 601 阅读 · 0 评论 -
LeetCode —— Valid Number
链接:http://leetcode.com/onlinejudge#question_65原题:Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueN原创 2013-09-03 09:31:48 · 927 阅读 · 0 评论 -
LeetCode —— Unique Binary Search Trees II
链接:http://leetcode.com/onlinejudge#question_95原题:Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program shoul原创 2013-09-03 09:26:25 · 716 阅读 · 0 评论 -
LeetCode -- Wildcard Matching
链接:http://leetcode.com/onlinejudge#question_44原题:Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (incl原创 2013-09-02 20:21:31 · 1388 阅读 · 0 评论 -
LeetCode —— Set Matrix Zeroes
链接:http://leetcode.com/onlinejudge#question_73原题:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A stra原创 2013-08-31 15:39:06 · 551 阅读 · 0 评论 -
LeetCode -- 二叉树水题II
Binary Tree Level Order Traversal链接:http://leetcode.com/onlinejudge#question_102原题:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by l原创 2013-04-21 22:43:01 · 704 阅读 · 0 评论 -
LeetCode —— Triangle
链接:http://leetcode.com/onlinejudge#question_120原题:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, giv原创 2013-04-20 20:58:25 · 512 阅读 · 0 评论 -
LeetCode —— Sqrt(x)
链接:http://leetcode.com/onlinejudge#question_69原题:Implement int sqrt(int x).Compute and return the square root of x.思路:测试用例中全是非负数,我是参考百度百科http://baike.baidu.com/view/239903.htm一个古老的算法,原原创 2013-04-18 15:24:44 · 700 阅读 · 0 评论 -
LeetCode —— Word Ladder
链接:http://leetcode.com/onlinejudge#question_127原题:Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:On原创 2013-04-18 13:10:01 · 1172 阅读 · 0 评论 -
LeetCode —— Longest Consecutive Sequence
链接:http://leetcode.com/onlinejudge#question_128原题:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3,原创 2013-04-17 22:23:22 · 725 阅读 · 0 评论 -
LeetCode —— Search for a Range
链接:http://leetcode.com/onlinejudge#question_34原题:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be i原创 2013-04-23 20:45:44 · 1089 阅读 · 0 评论 -
LeetCode —— Pow(x, n)
链接:http://leetcode.com/onlinejudge#question_50原题:Implement pow(x, n)思路:1次、2次、4次、8次这样算上去,其实就是n的二进制表示形式。当然要小心n是负数和底数是+1 和-1的时候,要优化。代码:class Solution {public: double pow(double x, in原创 2013-04-23 21:03:02 · 571 阅读 · 0 评论 -
LeetCode——Binary Tree Maximum Path Sum
链接:http://leetcode.com/onlinejudge#question_124原题:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary t原创 2013-04-13 23:39:55 · 1280 阅读 · 0 评论 -
LeetCode —— Palindrome Partition II
链接:http://leetcode.com/onlinejudge#question_132原题:Palindrome Partitioning IIGiven a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cu原创 2013-04-13 13:16:31 · 1115 阅读 · 2 评论 -
LeetCode —— Distinct Subsequences
链接:http://leetcode.com/onlinejudge#question_115原题:Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is fo原创 2013-04-22 13:41:56 · 828 阅读 · 0 评论 -
LeetCode —— Sudoku Solver
链接:http://leetcode.com/onlinejudge#question_37原题:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that th原创 2013-04-26 16:37:32 · 828 阅读 · 0 评论 -
LeetCode —— First Missing Positive
链接:http://leetcode.com/onlinejudge#question_41原题: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.Y原创 2013-04-26 16:15:07 · 547 阅读 · 0 评论 -
LeetCode —— Search in Rotated Sorted Array
链接:http://leetcode.com/onlinejudge#question_33原题: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 gi原创 2013-04-26 21:11:20 · 635 阅读 · 0 评论 -
LeetCode —— Edit Distance
链接:http://leetcode.com/onlinejudge#question_72原题: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.)原创 2013-04-20 19:59:46 · 539 阅读 · 0 评论 -
LeetCode -- Recover Binary Search Tree
链接:http://leetcode.com/onlinejudge#question_99原题:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n)原创 2013-04-21 21:28:33 · 873 阅读 · 0 评论 -
LeetCode——二叉树水题
Minimum Depth of Binary Tree链接:http://leetcode.com/onlinejudge#question_111原题:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path f原创 2013-04-13 23:59:59 · 1089 阅读 · 0 评论 -
LeetCode —— Decode Ways
链接:http://leetcode.com/onlinejudge#question_91原题:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an en原创 2013-04-20 19:24:39 · 592 阅读 · 0 评论 -
LeetCode ——Subsets II
链接:http://leetcode.com/onlinejudge#question_90原题:Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in n原创 2013-04-20 18:45:32 · 533 阅读 · 0 评论 -
LeetCode —— 3SUM
3Sum链接:http://leetcode.com/onlinejudge#question_15原题: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原创 2013-04-20 15:21:05 · 1041 阅读 · 0 评论 -
LeetCode —— Combinations
链接:http://leetcode.com/onlinejudge#question_77原题: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:原创 2013-04-19 23:17:28 · 523 阅读 · 0 评论