JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
上一页 1 ··· 14 15 16 17 18

2013年11月3日

摘要: use dynamic programming to exchange time with space. 1 public class Solution { 2 public int uniquePaths(int m, int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int[][] mytable = new... 阅读全文
posted @ 2013-11-03 15:00 JasonChang 阅读(146) 评论(0) 推荐(0) 编辑

摘要: very easy recursion1 public class Solution {2 public int maxDepth(TreeNode root) {3 // IMPORTANT: Please reset any member data you declared, as4 // the same Solution instance will be reused for each test case.5 if(root == null)6 return 0;7 return Math.... 阅读全文
posted @ 2013-11-03 13:50 JasonChang 阅读(134) 评论(0) 推荐(0) 编辑

摘要: 特殊值可先判断并返回 很重要本题是通过左移代替乘法产生不同的除数, 然后做减法得到解。 1 public class Solution { 2 public int divide(int dividend, int divisor) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(dividend == 0) 6 ... 阅读全文
posted @ 2013-11-03 12:58 JasonChang 阅读(299) 评论(0) 推荐(0) 编辑

摘要: 当数组为 1,2,3,4,.. i,.. n时,基于以下原则的BST建树具有唯一性:以i为根节点的树,其左子树由[0, i-1]构成, 其右子树由[i+1, n]构成。再由递归便可得:public static int numTrees(int n) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. int[] myarray = new int[n+... 阅读全文
posted @ 2013-11-03 11:04 JasonChang 阅读(197) 评论(0) 推荐(0) 编辑

上一页 1 ··· 14 15 16 17 18