摘要:
#coding=utf-8#点评:#递归思想加层次遍历,很经典的解题模板思想 20181220class Solution(object): def numSquares(self, n): """ :type n: int :rtype: int """ pair = (n,0) queue = 阅读全文
posted @ 2019-03-17 16:18
AceKo
阅读(197)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 16:17
AceKo
阅读(89)
评论(0)
推荐(0)
摘要:
class Solution(object): def evalRPN(self, tokens): """ :type tokens: List[str] :rtype: int """ stack = [] ops = ["+","-","*","/"] for i in tokens: if 阅读全文
posted @ 2019-03-17 16:16
AceKo
阅读(128)
评论(0)
推荐(0)
摘要:
class Solution(object): def postorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ class Command(object): def __init__(self,co 阅读全文
posted @ 2019-03-17 16:15
AceKo
阅读(155)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 16:14
AceKo
阅读(90)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 16:10
AceKo
阅读(201)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 16:09
AceKo
阅读(208)
评论(0)
推荐(0)
摘要:
class Solution(object): def ladderLength(self, beginWord, endWord, wordList): """ :type beginWord: str :type endWord: str :type wordList: List[str] :r 阅读全文
posted @ 2019-03-17 16:08
AceKo
阅读(168)
评论(0)
推荐(0)
摘要:
class Solution(object): def findLadders(self, beginWord, endWord, wordlist): """ :type beginWord: str :type endWord: str :type wordlist: Set[str] :rty 阅读全文
posted @ 2019-03-17 16:03
AceKo
阅读(120)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 16:02
AceKo
阅读(98)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 16:01
AceKo
阅读(190)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 16:00
AceKo
阅读(211)
评论(0)
推荐(0)
摘要:
class Solution(object): def inorderTraversal(self, root): """ :type root: TreeNode :rtype """ res = [] self.order(root, res) return res def order(self 阅读全文
posted @ 2019-03-17 15:58
AceKo
阅读(130)
评论(0)
推荐(0)
摘要:
class Solution(object): def inorderTraversal(self, root): """ :type root: TreeNode :rtype """ class Command(object): def __init__(self,com,node): self 阅读全文
posted @ 2019-03-17 15:58
AceKo
阅读(155)
评论(0)
推荐(0)
摘要:
#coding=utf-8#看到这种来来回回,增增删删的题,一般都想到用栈。#我们把字符串按照/分割之后就得到了每个文件的目录,然后判断路径是添加还是向上层进行返回。这个题很简单了。#有一个地方犯了小错误,不能写成if dir == ‘..’ and stack: stack.pop()。这样的话如 阅读全文
posted @ 2019-03-17 15:57
AceKo
阅读(83)
评论(0)
推荐(0)
摘要:
# Definition for singly-linked list.class ListNode(object): def __init__(self, x): self.val = x self.next = Noneclass Solution(object): def mergeKList 阅读全文
posted @ 2019-03-17 15:56
AceKo
阅读(89)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路:栈 20190302 找工作期间class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ stack = [] for i in s : if i == "( 阅读全文
posted @ 2019-03-17 15:55
AceKo
阅读(111)
评论(0)
推荐(0)
摘要:
# 1、在有序表中查找两数组指定的和,双指针法# 2、滑动窗口 : 连续子数组之和# 3、二分查找 : 顺序数组中查找特定的值# 4、递归程序的真正的构建是从底向上的,这就是为什么递归终止条件要写在最前面# 参见 反转链表的递归程序 LeetCode206# 5、 链表归并排序的递归过程,要好好体会 阅读全文
posted @ 2019-03-17 14:46
AceKo
阅读(482)
评论(0)
推荐(0)
摘要:
# 解题思路:字典存储计数信息 20190302 找工作期间class Solution(object): def fourSumCount(self, A, B, C, D): res2 = {} res = 0 for i in C: for j in D: res2[i + j] = res2 阅读全文
posted @ 2019-03-17 14:45
AceKo
阅读(104)
评论(0)
推荐(0)
摘要:
# 解题思路:字典存储计数信息 20190302 找工作期间class Solution(object): def frequencySort(self, s): """ :type s: str :rtype: str """ dict1 = {} result = str() for i in 阅读全文
posted @ 2019-03-17 14:44
AceKo
阅读(141)
评论(0)
推荐(0)
摘要:
# 解题思路:字典 20190302 找工作期间class Solution(object): def intersect(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] 阅读全文
posted @ 2019-03-17 14:43
AceKo
阅读(140)
评论(0)
推荐(0)
摘要:
# 解题思路:字典先存距离信息 20190302 找工作期间# n2class Solution: def numberOfBoomerangs(self, points): """ :type points: List[List[int]] :rtype: int """ def dis( poi 阅读全文
posted @ 2019-03-17 14:43
AceKo
阅读(158)
评论(0)
推荐(0)
摘要:
# 解题思路:无 20190302 找工作期间class Solution(object): def intersection(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[in 阅读全文
posted @ 2019-03-17 14:42
AceKo
阅读(90)
评论(0)
推荐(0)
摘要:
# 解题思路:字典解决其对应关系 20190302 找工作期间#使用字典,pattern当key,str当value,形成配对class Solution(object): def wordPattern(self, pattern, str): """ :type pattern: str :ty 阅读全文
posted @ 2019-03-17 14:39
AceKo
阅读(119)
评论(0)
推荐(0)
摘要:
# 解题思路:字典解决其对应关系 20190302 找工作期间class Solution(object): def isAnagram(self, s, t): """ :type s: str :type t: str :rtype: bool """ #字母异位词指字母相同,但排列不同的字符串 阅读全文
posted @ 2019-03-17 14:39
AceKo
阅读(195)
评论(0)
推荐(0)
摘要:
# 解题思路:用查找表(集合),保存其K个值的状态 遍历查找表时加上了限制条件T 20190302 找工作期间class Solution(object): def containsNearbyAlmostDuplicate(self, nums, k, t): """ :type nums: Li 阅读全文
posted @ 2019-03-17 14:38
AceKo
阅读(338)
评论(0)
推荐(0)
摘要:
# 解题思路:用查找表(集合),保存其K个值的状态 20190302 找工作期间class Solution(object): def containsNearbyDuplicate(self, nums, k): """ :type nums: List[int] :type k: int :rt 阅读全文
posted @ 2019-03-17 14:37
AceKo
阅读(143)
评论(0)
推荐(0)
摘要:
# 解题思路:字典存储计数状态 20190302 找工作期间class Solution(object): def containsDuplicate(self, nums): """ :type nums: List[int] :rtype: bool """ record = {} for i 阅读全文
posted @ 2019-03-17 14:36
AceKo
阅读(93)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路: 查找表 20190302 找工作期间class Solution(object): def isHappy(self, n): """ :type n: int :rtype: bool """ temp_res = [] while True: n = s 阅读全文
posted @ 2019-03-17 14:35
AceKo
阅读(101)
评论(0)
推荐(0)
摘要:
# 解题思路:字典建立隐射关系,一一对应 20190302 找工作期间class Solution(object): def isIsomorphic(self, s, t): """ :type s: str :type t: str :rtype: bool """ # 使用字典,pattern 阅读全文
posted @ 2019-03-17 14:35
AceKo
阅读(114)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路: 斜率查找表 20190302 找工作期间# Definition for a point.# class Point(object):# def __init__(self, a=0, b=0):# self.x = a# self.y = bclass S 阅读全文
posted @ 2019-03-17 14:34
AceKo
阅读(144)
评论(0)
推荐(0)
摘要:
class Solution(object): def groupAnagrams(self, strs): """ :type strs: List[str] :rtype: List[List[str]] """ ans, res, ret = [], {}, [] for s in strs: 阅读全文
posted @ 2019-03-17 14:33
AceKo
阅读(120)
评论(0)
推荐(0)
摘要:
# 解题思路:查找表 20190302 找工作期间# 哈希表能将查找的复杂度从o(n)降到 o(1)class Solution(object): def fourSum(self, nums, target): """ :type nums: List[int] :type target: int 阅读全文
posted @ 2019-03-17 14:32
AceKo
阅读(135)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路:查找表 n2 20190302 找工作期间# 排序数组的双指针求和法 : (0,n) -> (a,b)# 其中a只能增加 b只能减少 : 搜索方向的问题 ,不然会到重复的状态class Solution(object): def threeSum(self, 阅读全文
posted @ 2019-03-17 14:29
AceKo
阅读(138)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路: 排序 + 双指针求和 20190302 找工作期间class Solution(object): def threeSumClosest(self, nums, target): """ :type nums: List[int] :type target: 阅读全文
posted @ 2019-03-17 14:29
AceKo
阅读(133)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路:查找表 适合只有唯一解的情况 20190302 找工作期间class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int : 阅读全文
posted @ 2019-03-17 14:28
AceKo
阅读(186)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路:无 20190302 找工作期间class Solution(object): def moveZeroes(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, 阅读全文
posted @ 2019-03-17 14:26
AceKo
阅读(94)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路:排序 20190302 找工作期间class Solution: def findAnagrams(self, s, p): """ :type s: str :type p: str :rtype: List[int] """ from collection 阅读全文
posted @ 2019-03-17 14:26
AceKo
阅读(87)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路:快速排序 20190302 找工作期间# 关键点 index = partion(xx) ,index表示的是在整个数组中的位置class Solution(object): def findKthLargest(self, nums, k): """ :ty 阅读全文
posted @ 2019-03-17 14:25
AceKo
阅读(183)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路: 关键点:二分查找 20190302 找工作期间class Solution(object): def twoSum(self, numbers, target): """ :type numbers: List[int] :type target: int 阅读全文
posted @ 2019-03-17 14:24
AceKo
阅读(89)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路:滑动窗口 (本质上是搜索剪支) 20190302 找工作期间class Solution(object): def minSubArrayLen(self, s, nums): """ :type s: int :type nums: List[int] :r 阅读全文
posted @ 2019-03-17 14:24
AceKo
阅读(95)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路: 无 20190302 找工作期间class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: 阅读全文
posted @ 2019-03-17 14:23
AceKo
阅读(55)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路: 关键点:变量逻辑状态的定义 20190302 找工作期间class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ i 阅读全文
posted @ 2019-03-17 14:22
AceKo
阅读(186)
评论(0)
推荐(0)
摘要:
# 解题思路: 组合问题 20190302 找工作期间# (0,n)-> (a,b) 查找问题# 搜索树的 剪支 (0,n) -> [(0,n-1),(1,n)]#具体思路 :# 字典计数 然后判断搜索路径from collections import defaultdictclass Soluti 阅读全文
posted @ 2019-03-17 14:20
AceKo
阅读(77)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路: 三路排序法(借鉴快速排序的思想) 20190302 找工作期间class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: void Do not 阅读全文
posted @ 2019-03-17 14:19
AceKo
阅读(81)
评论(0)
推荐(0)
摘要:
# 解题思路: 无 20190302 找工作期间class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ k = 0 for 阅读全文
posted @ 2019-03-17 14:18
AceKo
阅读(113)
评论(0)
推荐(0)
摘要:
# 首先,两条线条之间的容积为(x2 - x1) * min(height[x1], height[x2])# 先取最左边直线和最右边直线,这种情况用(0, n-1)表示。# 下一步,考虑减少一个单位的宽度的情况,这时候有两种选择:(0, n-2)和(1, n-1)。# 对比这两种情况,如果线条的高 阅读全文
posted @ 2019-03-17 14:17
AceKo
阅读(183)
评论(0)
推荐(0)
摘要:
# 解题思路: 无 20190302 找工作期间class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ k = 0 if not nums: return 阅读全文
posted @ 2019-03-17 14:17
AceKo
阅读(102)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 解题思路:# 滑动窗口问题: 字典的使用是关键 map hash 表的使用 20190302 找工作期间class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rt 阅读全文
posted @ 2019-03-17 14:16
AceKo
阅读(150)
评论(0)
推荐(0)
摘要:
# coding: utf-8'''题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。'''class Node: def __init__(self, data, left, right): self.data = data se 阅读全文
posted @ 2019-03-17 14:14
AceKo
阅读(328)
评论(0)
推荐(0)
摘要:
#-*- coding:utf-8 -*-class Node: def __init__(self,data): self.data=data self.lchild=None self.rchild=Noneclass Tree: def __init__(self): self.queue=[ 阅读全文
posted @ 2019-03-17 14:13
AceKo
阅读(258)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 14:12
AceKo
阅读(126)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 14:11
AceKo
阅读(102)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = None# 思考误区:当只有根节点时 阅读全文
posted @ 2019-03-17 14:10
AceKo
阅读(59)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = None# 这是从底向上构建路径# 阅读全文
posted @ 2019-03-17 14:09
AceKo
阅读(76)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = None# 二叉树的公共祖先是什么? 阅读全文
posted @ 2019-03-17 14:08
AceKo
阅读(183)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None# 即中序遍历的第K个节点class S 阅读全文
posted @ 2019-03-17 14:07
AceKo
阅读(144)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = None# 二叉搜索树的公共祖先一定 阅读全文
posted @ 2019-03-17 14:07
AceKo
阅读(151)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 14:06
AceKo
阅读(90)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 14:05
AceKo
阅读(123)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 14:04
AceKo
阅读(101)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = None#coding=utf-8# 阅读全文
posted @ 2019-03-17 14:03
AceKo
阅读(151)
评论(0)
推荐(0)
摘要:
class Solution(object): def hasPathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: bool """ if not root: return False if root an 阅读全文
posted @ 2019-03-17 14:00
AceKo
阅读(97)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 13:59
AceKo
阅读(102)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 13:59
AceKo
阅读(115)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 13:57
AceKo
阅读(80)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solution(objec 阅读全文
posted @ 2019-03-17 13:57
AceKo
阅读(61)
评论(0)
推荐(0)
摘要:
#coding=utf-8# Definition for a binary tree node.class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None# 递归cla 阅读全文
posted @ 2019-03-17 13:56
AceKo
阅读(162)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2019-03-17 13:55
AceKo
阅读(134)
评论(0)
推荐(0)
摘要:
class Solution(object): def zhuhanshu(self,n): self.count = 0 self.memo = [-1 for i in range(n+1)] def fib1(self,n): if n == 0 or n == 1: return 1 els 阅读全文
posted @ 2019-03-17 13:54
AceKo
阅读(112)
评论(0)
推荐(0)
摘要:
class Solution(object): def zhuhanshu(self,n): self.count = 0 self.memo = [-1 for i in range(n+1)] def fib1(self,n): if n == 0 or n == 1: return 1 els 阅读全文
posted @ 2019-03-17 13:50
AceKo
阅读(204)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 最长公共子序列# s1[m] = s2[n]# LSC(m,n) = LSC(m-1,n-1) + 1# s1[m] != s2[n]# LSC= max(LSC(m-1,n),LSC(m,n-1))class Solution(object): def findlcs 阅读全文
posted @ 2019-03-17 13:49
AceKo
阅读(153)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 递归1 递归到底# 序列选与不选的模板题 o(2**n) 20190307 找工作期间class Solution1(object): def findTargetSumWays(self, nums, S): """ :type nums: List[int] :ty 阅读全文
posted @ 2019-03-17 13:48
AceKo
阅读(229)
评论(0)
推荐(0)
摘要:
# coding=utf8# 递归# 递归过程是错的,求子集过程错误class Solution1(object): def findMaxForm(self, strs, m, n): """ :type strs: List[str] :type m: int :type n: int :rty 阅读全文
posted @ 2019-03-17 13:47
AceKo
阅读(154)
评论(0)
推荐(0)
摘要:
# coding=utf8# 递归class Solution1(object): def combinationSum4(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ if not 阅读全文
posted @ 2019-03-17 13:46
AceKo
阅读(257)
评论(0)
推荐(0)
摘要:
# coding=utf8# 递归class Solution1(object): def combinationSum4(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ if not 阅读全文
posted @ 2019-03-17 13:45
AceKo
阅读(224)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 递归class Solution1(object): def wiggleMaxLength(self, nums): """ :type nums: List[int] :rtype: int """ self.res = 0 # 这是一个坑 ans = [] sel 阅读全文
posted @ 2019-03-17 13:14
AceKo
阅读(131)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 递归class Solution1(object): def integerBreak(self, n): """ :type n: int :rtype: int """ self.memo = [-1 for i in range(n+1)] # 将n进行分割(至少 阅读全文
posted @ 2019-03-17 13:11
AceKo
阅读(136)
评论(0)
推荐(0)
摘要:
#coding=utf-8# Definition for a binary tree node.class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None# 递归cla 阅读全文
posted @ 2019-03-17 13:10
AceKo
阅读(154)
评论(0)
推荐(0)
摘要:
# coding=utf-8# 递归class Solution1(object): def coinChange(self, coins, amount): """ :type coins: List[int] :type amount: int :rtype: int """ if not co 阅读全文
posted @ 2019-03-17 13:08
AceKo
阅读(219)
评论(0)
推荐(0)
摘要:
#coding=utf-8# leetcode 312 解题报告 20190307 找工作期间#解题思路# 假设初始气球的状态是 [3,1,5,8]#、顺向思维# 第一步有四个选择:3,1,5,8 ,# 第二步有三个选择:…… o(n!)# 每一步后 原问题的规模是减少了 ,但是数据的同质性却破坏了 阅读全文
posted @ 2019-03-17 13:06
AceKo
阅读(311)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 递归class Solution1(object): def maxCoins(self, nums): """ :type nums: List[int] :rtype: int """ self.res = 0 if not nums: return self.re 阅读全文
posted @ 2019-03-17 13:04
AceKo
阅读(186)
评论(0)
推荐(0)
摘要:
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ length = len(prices) if length <= 1: return 0 hold = 阅读全文
posted @ 2019-03-17 13:03
AceKo
阅读(471)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 递归1### 选与不选 经典的组合问题class Solution1(object): def lengthOfLIS(self, nums): """ :type nums: List[int] :rtype: int """ self.res = 0 if not 阅读全文
posted @ 2019-03-17 13:00
AceKo
阅读(599)
评论(0)
推荐(0)
摘要:
#coding=utf-8#点评:#递归思想加层次遍历,很经典的解题模板思想 20181220class Solution(object): def numSquares(self, n): """ :type n: int :rtype: int """ pair = (n,0) queue = 阅读全文
posted @ 2019-03-17 12:57
AceKo
阅读(151)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 递归版class Solution1(object): def numSquares(self, n): """ :type n: int :rtype: int """ return self.squareNum(n) def squareNum(self,n): i 阅读全文
posted @ 2019-03-17 12:57
AceKo
阅读(211)
评论(0)
推荐(0)
摘要:
class Solution(object): def rob(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: return 0 length = len(nums) if length == 1: return 阅读全文
posted @ 2019-03-17 12:55
AceKo
阅读(151)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 1# 对状态的定义 : 考虑偷取[x...n-1]范围里的房子class Solution1(object): def rob(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: ret 阅读全文
posted @ 2019-03-17 12:54
AceKo
阅读(99)
评论(0)
推荐(0)
摘要:
#coding=utf-8#递归class Solution1(object): def rob(self, nums): """ :type nums: List[int] :rtype: int """ return self.tryRob(nums,0) # 考虑抢劫nums[index,.. 阅读全文
posted @ 2019-03-17 12:53
AceKo
阅读(123)
评论(0)
推荐(0)
摘要:
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if not prices: return 0 buy = [0 for i in range(len(p 阅读全文
posted @ 2019-03-17 12:52
AceKo
阅读(379)
评论(0)
推荐(0)
摘要:
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if not prices: return 0 buy = -prices[0] sell = 0 for 阅读全文
posted @ 2019-03-17 12:50
AceKo
阅读(338)
评论(0)
推荐(0)
摘要:
class Solution1(object): def minimumTotal(self, triangle): """ :type triangle: List[List[int]] :rtype: int """ self.dp(triangle) # i # i , i+1 def dp( 阅读全文
posted @ 2019-03-17 12:49
AceKo
阅读(242)
评论(0)
推荐(0)
摘要:
#coding=utf-8class Solution1(object): def numDecodings(self, s): """ :type s: str :rtype: int """ if not s: return return self.decode(s) pass def deco 阅读全文
posted @ 2019-03-17 12:45
AceKo
阅读(148)
评论(0)
推荐(0)
摘要:
class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int """ self.memo = [-1 for i in range(n+1)] return self.calcWays1(n) def c 阅读全文
posted @ 2019-03-17 12:44
AceKo
阅读(175)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 按递归的逆顺序 从底向上class Solution1(object): def minPathSum(self, grid): """ :type grid: List[List[int]] :rtype: int """ self.m = len(grid) sel 阅读全文
posted @ 2019-03-17 12:41
AceKo
阅读(202)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 递归# dfsclass Solution1(object): def uniquePathsWithObstacles(self, obstacleGrid): """ :type obstacleGrid: List[List[int]] :rtype: int " 阅读全文
posted @ 2019-03-17 12:40
AceKo
阅读(154)
评论(0)
推荐(0)
摘要:
作者:tornadomeet 出处:http://www.cnblogs.com/tornadomeet 机器学习&数据挖掘笔记_16(常见面试之机器学习算法思想简单梳理) 前言: 找工作时(IT行业),除了常见的软件开发以外,机器学习岗位也可以当作是一个选择,不少计算机方向的研究生都会接触这个,如 阅读全文
posted @ 2019-03-17 12:33
AceKo
阅读(117)
评论(0)
推荐(0)
摘要:
#coding=utf-8# 递归# 深度优先遍历,找全路径 20190306 找工作期间class Solution1(object): def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: int """ if m 阅读全文
posted @ 2019-03-17 12:29
AceKo
阅读(169)
评论(0)
推荐(0)
摘要:
01 背包问题 阅读全文
posted @ 2019-03-17 12:11
AceKo
阅读(229)
评论(0)
推荐(0)

浙公网安备 33010602011771号