摘要: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo 阅读全文
posted @ 2017-01-29 13:24 CodesKiller 阅读(110) 评论(0) 推荐(0)
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2, 阅读全文
posted @ 2017-01-29 12:45 CodesKiller 阅读(126) 评论(0) 推荐(0)
摘要: 区别:动态规划全局最优解中一定包含某个局部最优解,但不一定包含前一个局部最优解,因此需要记录之前的所有最优解。条件:最优子结构;重叠子问题。方法:自底向上构造子问题的解。例子:子序列最大和问题,滑雪问题 贪心算法条件:每一步的最优解一定依赖上一步的最优解。方法:从问题的某一个初始解出发逐步逼近给定的 阅读全文
posted @ 2017-01-29 12:29 CodesKiller 阅读(698) 评论(0) 推荐(1)
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4],t 阅读全文
posted @ 2017-01-29 12:21 CodesKiller 阅读(109) 评论(0) 推荐(0)
摘要: 概述:动态规划在查找有很多重叠子问题的情况的最优解时有效。他将问题重新组合成子问题。为了避免多次解决这些子问题,他们的结果都逐渐被计算并被保存。因此,动态规划保存递归时的结果,因而不会在解决同样的问题时花费时间。 动态规划只能应用于最优子结构问题,最优子结构的意思是局部最优解能决定全局最优解(对有些 阅读全文
posted @ 2017-01-29 11:21 CodesKiller 阅读(184) 评论(0) 推荐(0)
摘要: Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except  阅读全文
posted @ 2017-01-29 06:30 CodesKiller 阅读(130) 评论(0) 推荐(0)
摘要: Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to 阅读全文
posted @ 2017-01-29 05:39 CodesKiller 阅读(276) 评论(0) 推荐(0)
摘要: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. 阅读全文
posted @ 2017-01-29 04:23 CodesKiller 阅读(143) 评论(0) 推荐(0)
摘要: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo 阅读全文
posted @ 2017-01-29 03:48 CodesKiller 阅读(88) 评论(0) 推荐(0)