- 博客(6)
- 资源 (3)
- 收藏
- 关注
原创 Leetcode之 largest divisible set
题目题目地址 :https://leetcode.com/problems/largest-divisible-subset/题意解析给定一个数组,这个数组数唯一且为正数,求在这个数组中,满足能整除的最大集合。求解很自然地想到用动态,因为满足重叠子问题和最优子结构 重叠子问题:整个数组的最大集合,可以认为是多个子问题组成的 最优子结构:反证法,显而易见。 定义最优解:最大集合是什么。定义最优解
2016-08-13 14:23:28 710
原创 Leetcode 之Search a 2D Matrix
题目https://leetcode.com/problems/search-a-2d-matrix/题意解析在二维数组中找一个数,这个二维数组满足2个特性 同一行中的数字右边的比左边的大。 下一行的第一个数比上一行的最后一个数大。 求解应该找到这样的一个点,使得这样一个点和target数比较的时候如果小于只能是在其左边找,大于则只能在其下方找,想找这样的理由是根据二维数组的特性得到的。如果是从第一
2016-08-12 10:58:57 407
原创 Leetcode之Unique Paths II
题目 题目地址:https://leetcode.com/problems/unique-paths-ii/题意解析题目的意思还是求路径,不过路径中会存在阻碍,阻碍的位置将不能通过。这个是和前一个问题中不一样的地方,也因为这样,难度升高了一点点。求解定义最优解:最优解为从原点出发的所有路径。 定义最优解的值:这样的路径有多少个。递归式表示最优解的值:f[i,j] 表示从[0,0]出发到[i,j
2016-08-11 11:16:38 332
原创 Leetcode 之 Unique Paths
题目 原题目地址:https://leetcode.com/problems/unique-paths/ 题意解析题目的意思是给定一个二维数组网格,从原点(0,0)出发到达最末尾总共有几种路径做法,每次操作的时候只能向右或者向下。 一看到题意 就让我很自然地想到了动态规划,DP问题需要满足2个条件:重叠子问题和最优子结构 其中 重叠子问题:显然满足情况。 最优子结构:也满足,可以用反证法。 定
2016-08-10 21:43:29 521
原创 Leetcode 之 Insert Delete GetRandom O(1)
题目Design a data structure that supports all following operations in average O(1) time. insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val from the set
2016-08-09 18:32:25 1293
原创 Leetcode之Search for a Range
Search for a Range 题目Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the targ
2016-08-07 23:33:38 908 2
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人