摘要:
1.此题很勉强算DP。找了半天网上思路,是个三层的循环,n^3。2.基本思路就是先找到在第一个位置的花。这样就双层遍历,找到所有和其他不冲突的花中最高的一个,然后放到结果的首位。然后去掉此花,继续使用此方法对余下花朵。3.要注意的是首先不能直接排序,比如a和b,b和c有冲突,但a和c不一定有冲突。4.判断两段是否重叠的最简单式子是!(a.start > b.end || b.start > a.end)思路来自:http://apps.topcoder.com/forums/?module=Thread&threadID=655393&start=0&mc= 阅读全文
posted @ 2013-08-13 23:32
阿牧遥
阅读(657)
评论(0)
推荐(0)
摘要:
此题是道神题。一开始我也像参考链接http://www.cnblogs.com/lichen782/p/Leetcode_Trapping_Rain_Water.html里面一样想了许久想到“俄罗斯方块”想法。但复杂度不够好。 后来看了方法二,确实巧妙。“其实,本质上来说,第一步保障了左右两边的水总 阅读全文
posted @ 2013-08-13 22:09
阿牧遥
阅读(325)
评论(0)
推荐(0)
摘要:
不难。就是比如到了[0, 1, 3, 2]时,下一组就要[4+2, 3+2, 1+2, 0+2]。但是当时没有做到ans.add(0)一开始初始化(而是只放在n==0的判断block内了),所以runtime error了。看了半天看出来了。public class Solution { public ArrayList grayCode(int n) { // Start typing your Java solution below // DO NOT write main() function ArrayList ans = new Arr... 阅读全文
posted @ 2013-08-13 21:17
阿牧遥
阅读(165)
评论(0)
推荐(0)
摘要:
动态规划。再最左和最上加了0的一行一列。但是一开始忘了把mx[1][1]设成1了。public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { // Start typing your Java solution below // DO NOT write main() function int m = obstacleGrid.length; if (m == 0) return 0; int n = obsta... 阅读全文
posted @ 2013-08-13 20:49
阿牧遥
阅读(173)
评论(0)
推荐(0)
摘要:
动态规划。就是要注意第0行和第0列的初始化。 public class Solution { public int minPathSum(int[][] grid) { // Start typing your Java solution below // DO NOT write main() f 阅读全文
posted @ 2013-08-13 20:38
阿牧遥
阅读(148)
评论(0)
推荐(0)

浙公网安备 33010602011771号