摘要: 简单题。public class Solution { public int jump(int[] A) { // Start typing your Java solution below // DO NOT write main() function int len = A.length; if (len == 0 || len == 1) return 0; int[] m = new int[len]; m[0] = 0; int max = 0; in... 阅读全文
posted @ 2013-08-12 23:29 阿牧遥 阅读(196) 评论(0) 推荐(0)
摘要: 整体不难,一开始以为是线段树,后来仔细看来不需要,从左到右扫,判断是否要merge就是了。此题有几个要注意的地方:1.Java的Comparator要会写;2.循环结束后的ans.add(tmp)不要忘记;3.merge的时候,左右边界要计算一下。 /** * Definition for an i 阅读全文
posted @ 2013-08-12 22:55 阿牧遥 阅读(1245) 评论(0) 推荐(0)
摘要: 简单题。public class Solution { public int lengthOfLastWord(String s) { // Start typing your Java solution below // DO NOT write main() function int len = s.length(); if (len == 0) return 0; boolean meetWord = false; int count = 0; for (int i =... 阅读全文
posted @ 2013-08-12 22:07 阿牧遥 阅读(155) 评论(0) 推荐(0)
摘要: 动态规划。巧妙的是通过在最上和最左边加一条0的线,大大简化了编程实现。public class Solution { public int uniquePaths(int m, int n) { // Start typing your Java solution below // DO NOT write main() function int[][] mx = new int[m+1][n+1]; for (int i = 0; i < m+1; i++) { mx[i][0] = 0; ... 阅读全文
posted @ 2013-08-12 21:57 阿牧遥 阅读(202) 评论(0) 推荐(0)
摘要: 这道题果然不容易写对啊。首先为了写对,我写完以后对着代码又检查了一阵,挺好,而且发现自己偶尔写点注释也便于自己理解。然后居然超时了,主要原因就是计算长度为n的空字符串花时间太多,就用了个数组一开始先算好存起来。这里用new String[L+1]主要为了避免L为0的情况。public class Solution { public ArrayList fullJustify(String[] words, int L) { // Start typing your Java solution below // DO NOT write main() funct... 阅读全文
posted @ 2013-08-12 21:47 阿牧遥 阅读(465) 评论(0) 推荐(0)