2015年5月21日
摘要: 斐波那契 f(n) = f(n -1) + f(n -2);public class Solution { public int climbStairs(int n) { int f1 = 1; int f2 = 2; if (n == 1) { ... 阅读全文
posted @ 2015-05-21 15:32 kikiUr 阅读(98) 评论(0) 推荐(0) 编辑
摘要: buttom-up DP这是一道动态规划的题目,求一个三角形二维数组从顶到低端的最小路径和。思路是维护到某一个元素的最小路径和,那么在某一个元素i,j的最小路径和就是它上层对应的相邻两个元素的最小路径和加上自己的值,递推式是sum[i][j]=min(sum[i-1][j-1],sum[i-1][j... 阅读全文
posted @ 2015-05-21 15:01 kikiUr 阅读(114) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int m = obstacleGrid.length; int n = obstacleGrid... 阅读全文
posted @ 2015-05-21 11:41 kikiUr 阅读(104) 评论(0) 推荐(0) 编辑
摘要: code ganker:http://codeganker.blogspot.com/2014/03/unique-paths-leetcode.htmlpublic class Solution { public int uniquePaths(int m, int n) { ... 阅读全文
posted @ 2015-05-21 11:24 kikiUr 阅读(83) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public boolean exist(char[][] board, String word) { if (board == null || board.length == 0) { return false... 阅读全文
posted @ 2015-05-21 10:26 kikiUr 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 递归public class Solution { public ArrayList preorderTraversal(TreeNode root) { ArrayList res = new ArrayList(); traversal(root, res); ... 阅读全文
posted @ 2015-05-21 06:32 kikiUr 阅读(141) 评论(0) 推荐(0) 编辑