simon717
simon717
全部文章
未归档
归档
标签
去牛客网
登录
/
注册
simon的小屋
施工中...
全部文章
/ 未归档
(共84篇)
递归的两种情况
递归 和 DP 是不是都可以 自底向上 和 自顶向下 ?? 之前的认知是 DP是自底向上 递归是自顶向下 好像这个认知没啥问题 递归就是要把大问题转成小问题 逐个解决 DP从最小的问题开始递推到最终要解决的大问题 从头计算到后面 (小偷问题) """ 递归 + me...
2019-04-12
0
447
DP 递归 递归 + 缓存
最近发现DP的本质就是递归 + 缓存 占坑 后续补 经典的例子 爬楼梯 最小编辑距离 ... naive 递归 递归 + memo 直接DP leetcode 72. Edit Distance 最小编辑距离 第一版解 很容易想到的递归解 class Solution(obj...
2019-04-12
0
359
经典DP 青蛙跳
一种是 f(n) = f(n-1) + f(n-2) 变态青蛙跳 考虑第一步走多远 1 2 ... n f(n) = f(n-1) + f(n-2) + ... + f(n-(n-1)) + f(n-n) f(n) = f(n-1) + f(n-2) + ... + f(1) + f(0) f(n...
2019-04-10
0
313
旋转数组的最小下标
很简单很基础 第一种 我们最先就判断能否直接命中target 保证了后面的判断中target不可能被漏掉 因为mid不可能是target class Solution(object): def findMin(self, nums): """ ...
2019-04-02
0
420
33. Search in Rotated Sorted Array
这道题一开始看半天没有弄明白 后来恍然大悟 直接看注释 基于常规二分查找算法 重点在于 我们确定lr边界变化的时候需要考虑mid所在不同分段存在不同情况 class Solution(object): def search(self, nums, target): left...
2019-04-01
0
341
234. Palindrome Linked List
知识点: 快慢指针 链表反转 链表反转的四行代码必须熟记 class Solution: def isPalindrome(self, head): # 找到链表终中点 考虑奇数偶数两种情况 最终slow的位置正中间(奇数) 中间偏右的节点(偶数) ...
2019-03-25
0
380
22. Generate Parentheses
https://github.com/apachecn/awesome-algorithm/blob/master/docs/Leetcode_Solutions/Python/0022._generate_parentheses.md 关于回溯法讲解的很好 三原则: 选择 限制 ...
2019-03-25
0
374
连续子序列优化问题 DP通解
第一题:https://leetcode.com/problems/maximum-subarray/ Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. 思路:动态规划...
2019-03-24
0
638
leetcode 46 permutation
先看一道permutation leetcode 46 Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] Output: [ [1,2,3], [1...
2019-03-24
0
400
剑指offer 机器人的运动范围
思想:回溯 实现: class Solution_: def movingCount(self, threshold, rows, cols): # write code here if rows < 1 or cols < 1 or thres...
2019-03-23
0
356
首页
上一页
1
2
3
4
5
6
7
8
9
下一页
末页