摘要:
斐波那契 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) { ... 阅读全文
摘要:
buttom-up DP这是一道动态规划的题目,求一个三角形二维数组从顶到低端的最小路径和。思路是维护到某一个元素的最小路径和,那么在某一个元素i,j的最小路径和就是它上层对应的相邻两个元素的最小路径和加上自己的值,递推式是sum[i][j]=min(sum[i-1][j-1],sum[i-1][j... 阅读全文
摘要:
public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int m = obstacleGrid.length; int n = obstacleGrid... 阅读全文
摘要:
code ganker:http://codeganker.blogspot.com/2014/03/unique-paths-leetcode.htmlpublic class Solution { public int uniquePaths(int m, int n) { ... 阅读全文
摘要:
public class Solution { public boolean exist(char[][] board, String word) { if (board == null || board.length == 0) { return false... 阅读全文
摘要:
递归public class Solution { public ArrayList preorderTraversal(TreeNode root) { ArrayList res = new ArrayList(); traversal(root, res); ... 阅读全文