码迷,mamicode.com
首页 >  
搜索关键字:leetcode 19    ( 34993个结果
【leetcode】Simplify Path
题目:将给定的路径名简化,返回最简形式。 path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" 虽然咋看起来比较杂乱,但还是比较整齐的,每个部分由‘/‘进行分割,就像文本处理中,由空格或tab分割的单词一样,对得到的不同的分割此进行不同的处理。得到的可能的分割词包括: string simplifyP...
分类:其他好文   时间:2014-05-26 06:13:24    阅读次数:213
【leetcode】Unique Paths II
题目:与版本一不同的是,这里给定了一个矩阵,矩阵中元素为0的点表示该点可达,为1的点表示不可达,当然,不可达也就意味着不可经过。以左上角为出发点,右下角为目标终点,可行的不同路径有多少。 分析: 在Uniqu Paths I 的基础上,加上对矩阵可达性的判断就可以了。 注意: 1.左上角的元素是1的时候,即出发点就不可达,即出发不了,倒在了起跑线上。 2.给定的矩阵是1*1的形式。 3...
分类:其他好文   时间:2014-05-26 05:48:24    阅读次数:247
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 exact...
分类:其他好文   时间:2014-05-25 00:46:51    阅读次数:229
LeetCode: Spiral Matrix [058]
【题目】 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 ] ] You should return [1,2,3,6,9,8,7,4,5]. 【题意】 螺旋输出MxN...
分类:其他好文   时间:2014-05-24 23:11:02    阅读次数:279
LeetCode: Maximum Subarray [052]
【题目】 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] has the largest sum = 6. 【题意】 给定一个数组,找出和最大的子数组,返回...
分类:其他好文   时间:2014-05-24 22:19:17    阅读次数:260
Unique Paths
题目:给定一个由参数m,n表示行数和列数而形成的2维表格,以左上为出发点,右下为目的地,每次只能向右走一步,或者向下走一步,算出总共存在多少不同的到达路径。 分析;这个问题的递归属性是很明显的,因为无论向右走还是向下走,到达一个新的位置,这时就变成了在该新位置到达目的地有多少不同的路径。其次,向右走和向下走是不同的路径,最终的结果应该是二者的和。 递归的返回条件:n = 1 或 m = 1, ...
分类:其他好文   时间:2014-05-24 21:58:45    阅读次数:243
LeetCode: Jump Game [054]
【题目】 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 if you are able to reach the last index. For example:...
分类:其他好文   时间:2014-05-24 20:44:39    阅读次数:221
【LeetCode】Sort Colors
题目 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 order red, white and blue. Here, we will use the i...
分类:其他好文   时间:2014-05-24 20:30:21    阅读次数:342
LeetCode: Merge Intervals [055]
【题目】 Given an array of non-negative integers, you are initially positioned at the first index of the array. 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]. ...
分类:其他好文   时间:2014-05-24 14:18:27    阅读次数:193
[leetcode]_Climbing Stairs
我敢保证这道题是在今早蹲厕所的时候突然冒出的解法。第一次接触DP题,我好伟大啊啊啊~题目:一个N阶的梯子,一次能够走1步或者2步,问有多少种走法。解法:原始DP问题。思路:1、if N == 1 , then ans = 1;2、if N == 2 , then ans = 2;3、if 我们现在在...
分类:其他好文   时间:2014-05-24 09:52:30    阅读次数:180
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!