随笔分类 -  Leetcode

1 2 3 4 5 ··· 7 下一页

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,... 阅读全文

posted @ 2015-01-15 21:46 Ryan-Xing 阅读(108) 评论(0) 推荐(0)

Leetcode:Container With Most Water
摘要:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of ... 阅读全文

posted @ 2015-01-15 16:43 Ryan-Xing 阅读(184) 评论(0) 推荐(0)

Leetcode:Best Time to Buy and Sell Stock II
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文

posted @ 2015-01-15 11:57 Ryan-Xing 阅读(105) 评论(0) 推荐(0)

Leetcode:Best Time to Buy and Sell Stock
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文

posted @ 2015-01-15 11:39 Ryan-Xing 阅读(107) 评论(0) 推荐(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 maximu... 阅读全文

posted @ 2015-01-15 11:28 Ryan-Xing 阅读(91) 评论(0) 推荐(0)

Leetcode:Pow(x, n)
摘要:Implement pow(x,n).分析:分治法。代码如下:class Solution {public: double pow(double x, int n) { if(n < 0) return 1.0/power(x, -n); return power(... 阅读全文

posted @ 2015-01-14 21:45 Ryan-Xing 阅读(116) 评论(0) 推荐(0)

Leetcode:Sqrt(x)
摘要:Implementint sqrt(int x).Compute and return the square root ofx.分析:二分查找。首先确定二分查找终止的条件和返回条件,其次对于与数字有关的题要注意int的表示范围防止溢出(比如该题两个int相乘可能会超过int的范围,故采用x/mid与... 阅读全文

posted @ 2015-01-14 21:44 Ryan-Xing 阅读(201) 评论(0) 推荐(0)

Leetcode:Combination Sum II
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number ... 阅读全文

posted @ 2015-01-14 14:22 Ryan-Xing 阅读(111) 评论(0) 推荐(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 i... 阅读全文

posted @ 2015-01-13 22:24 Ryan-Xing 阅读(181) 评论(0) 推荐(0)

Leetcode:Unique Paths
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文

posted @ 2015-01-13 22:04 Ryan-Xing 阅读(158) 评论(0) 推荐(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 perm... 阅读全文

posted @ 2015-01-13 14:49 Ryan-Xing 阅读(154) 评论(0) 推荐(0)

Leetcode:Permutations
摘要:Given a collection of 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,... 阅读全文

posted @ 2015-01-12 16:19 Ryan-Xing 阅读(191) 评论(0) 推荐(0)

Leetcode:Palindrome Partitioning II
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs... 阅读全文

posted @ 2015-01-08 11:59 Ryan-Xing 阅读(134) 评论(0) 推荐(0)

Leetcode:Search a 2D Matrix
摘要:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文

posted @ 2015-01-06 16:43 Ryan-Xing 阅读(108) 评论(0) 推荐(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 or... 阅读全文

posted @ 2015-01-06 16:31 Ryan-Xing 阅读(98) 评论(0) 推荐(0)

Leetcode:First Missing Positive
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文

posted @ 2015-01-06 15:37 Ryan-Xing 阅读(147) 评论(0) 推荐(0)

Leetcode:Merge Sorted Array
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal... 阅读全文

posted @ 2015-01-06 14:14 Ryan-Xing 阅读(156) 评论(0) 推荐(0)

Leetcode:Binary Search Tree Iterator
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next... 阅读全文

posted @ 2015-01-06 12:41 Ryan-Xing 阅读(224) 评论(0) 推荐(0)

Leetcode:Unique Binary Search Trees
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1... 阅读全文

posted @ 2015-01-05 23:53 Ryan-Xing 阅读(182) 评论(0) 推荐(0)

Leetcode:Symmetric Tree
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文

posted @ 2015-01-02 20:57 Ryan-Xing 阅读(175) 评论(0) 推荐(0)

1 2 3 4 5 ··· 7 下一页