2015年5月22日
摘要: 找规律:题解:本文讲解转自Code Ganker稍稍修改“http://blog.csdn.net/linhuanmars/article/details/20434115”“这道题是给定一个数组和一个排列,求下一个排列。算法上其实没有什么特别的地方,主要的问题是经常不是一见到这个题就能马上理清思路... 阅读全文
posted @ 2015-05-22 14:44 kikiUr 阅读(99) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int maxSubArray(int[] nums) { if (nums == null || nums.length <= 0) { return 0; } in... 阅读全文
posted @ 2015-05-22 10:04 kikiUr 阅读(79) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int searchInsert(int[] nums, int target) { if(nums == null || nums.length == 0) { return 0; ... 阅读全文
posted @ 2015-05-22 09:08 kikiUr 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 题解:根据题目要求,最多进行两次买卖股票,而且手中不能有2只股票,就是不能连续两次买入操作。所以,两次交易必须是分布在2各区间内,也就是动作为:买入卖出,买入卖出。进而,我们可以划分为2个区间[0,i]和[i,len-1],i可以取0~len-1。那么两次买卖的最大利润为:在两个区间的最大利益和的最... 阅读全文
posted @ 2015-05-22 08:49 kikiUr 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 从前往后扫一遍, 相邻两个数之差大于零的话就加到结果。public class Solution { public int maxProfit(int[] prices) { if (prices == null || prices.length == 0) { ... 阅读全文
posted @ 2015-05-22 08:02 kikiUr 阅读(97) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int maxProfit(int[] prices) { if(prices == null || prices.length == 0) { return 0; } ... 阅读全文
posted @ 2015-05-22 08:01 kikiUr 阅读(145) 评论(0) 推荐(0) 编辑
  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) 编辑