
Leetcode
Purogram
..
展开
-
[Leetcode] 42. Trapping Rain Water
好巧妙,双指针法,找到顶峰,左边开始数到最大,再从右边开始数到最大。class Solution(object): def trap(self, height): """ :type height: List[int] :rtype: int """ if len(height)<=2:原创 2017-04-15 18:57:24 · 237 阅读 · 0 评论 -
[Leetcode] 576. Out of Boundary Paths
原方法参见博文:http://www.cnblogs.com/grandyang/p/6927921.htmlhere is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid bo转载 2017-09-03 18:16:55 · 427 阅读 · 0 评论 -
[Leetcode] 646. Maximum Length of Pair Chain
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b . Chain原创 2017-09-03 00:11:05 · 511 阅读 · 0 评论 -
[Leetcode] 44. 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 cov原创 2017-08-27 16:02:28 · 265 阅读 · 0 评论 -
[Leetcode] 12. Integer to Roman
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.因为罗马计数对于每一位数字计数规则都是一样的,所以我们可以给个、十、百、千位都打一张罗马计数表,然后把输入的数字按位逐次表示出来,就OKAY了,非常简单机械的方法。但是由原创 2017-08-24 21:51:03 · 298 阅读 · 0 评论 -
[Leetcode] 403. Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.Given a list of原创 2017-08-12 23:36:21 · 374 阅读 · 0 评论 -
[Leetcode] 3. 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 "原创 2017-07-17 22:19:45 · 241 阅读 · 0 评论 -
[Leetcode] 39. Combination Sum
Given a set of candidate numbers (C) (without duplicates) 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原创 2017-08-01 14:59:03 · 264 阅读 · 0 评论 -
[Leetcode] 32. 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 parentheses substring is "()",原创 2017-07-17 17:11:11 · 208 阅读 · 0 评论 -
[Leetcode] 21. 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.合并两个有序链表,只允许通过两个链表相互插接的方式自己写怎么也写不出,后来才知道用递归做,既简洁又高效率。原创 2017-07-17 10:39:26 · 262 阅读 · 0 评论 -
[Leetcode] 617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tr原创 2017-07-14 14:53:57 · 972 阅读 · 0 评论 -
[Leetcode] 135. Candy
题目:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at原创 2017-05-12 21:19:41 · 206 阅读 · 0 评论 -
[Leetcode] 15. 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.无限超时。。。最后用这个O(n2)复杂度class Sol原创 2017-04-15 23:23:01 · 241 阅读 · 0 评论 -
[Leetcode] 11. 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, ai) and (i, 0). Fin原创 2017-05-12 15:22:27 · 225 阅读 · 0 评论 -
[Leetcode] 47. 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,1原创 2017-09-29 20:57:16 · 305 阅读 · 0 评论