LeetCode
Minkowski_lin
这个作者很懒,什么都没留下…
展开
-
LeetCode695 岛屿的最大面积(DFS)
LeetCode695 岛屿的最大面积(DFS)class Solution: def __init__(self): self.tmp = 0 def maxAreaOfIsland(self, grid: 'List[List[int]]') -> 'int': w = len(grid) h =len(grid[0]...原创 2019-02-25 17:31:05 · 286 阅读 · 0 评论 -
LeetCode279. 完全平方数(DP+四平方和)
LeetCode279. 完全平方数(DP+四平方和)转化为完全背包的DP问题from math import sqrtclass Solution: def numSquares(self, n: int) -> int: ans = n maxn = int(sqrt(n)) dp = [_ for _ in range(...原创 2019-03-08 12:52:53 · 341 阅读 · 0 评论 -
LeetCode743. 网络延迟时间(Dijkstra算法)
LeetCode743. 网络延迟时间(Dijkstra算法)codeclass Solution: def networkDelayTime(self, times: list, N: int, K: int) -> int: inf = int(1e9) g = [[int(1e9)] * N for _ in range(N)] ...原创 2019-03-12 00:21:48 · 1258 阅读 · 0 评论 -
LeetCode45. 跳跃游戏 II
LeetCode45. 跳跃游戏 IIclass Solution: def jump(self, nums): """ :type nums: List[int] :rtype: int """ cnt, s, e, far = 0, 0, 0, 0 while far <原创 2019-03-04 20:40:41 · 139 阅读 · 0 评论 -
LeetCode135. 分发糖果
LeetCode135. 分发糖果画折线图理解class Solution: def candy(self, ratings: list) -> int: cnt = 1 tmp = 1 l = 1 r = 0 for i in range(1, len(ratings)): ...原创 2019-03-04 19:09:23 · 235 阅读 · 0 评论 -
LeetCode142. 环形链表 II(快慢指针)
快慢指针参考https://zhuanlan.zhihu.com/p/30990994?utm_source=qq&utm_medium=social&utm_oi=1080275092017270784# Definition for singly-linked list.class ListNode(object): def __init__(self, x):...原创 2019-03-06 23:45:18 · 181 阅读 · 0 评论 -
LeetCode141. 环形链表(快慢指针)
LeetCode141. 环形链表(快慢指针)快慢指针参考https://zhuanlan.zhihu.com/p/30990994?utm_source=qq&utm_medium=social&utm_oi=1080275092017270784# Definition for singly-linked list.class ListNode(object): ...原创 2019-03-06 23:17:35 · 262 阅读 · 0 评论 -
LeetCode112.路径总和
LeetCode112.路径总和version 1# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solution: ...原创 2019-02-27 09:46:06 · 122 阅读 · 0 评论 -
LeetCode104.二叉树的最大深度 (BFS)+(递归)两种方法
LeetCode104.二叉树的最大深度 (BFS)+(递归)两种方法BFS# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None ...原创 2019-02-26 15:52:07 · 490 阅读 · 0 评论 -
LeetCode111. 二叉树的最小深度 (BFS) + (递归)两种方法
LeetCode111. 二叉树的最小深度 (BFS) + (递归)两种方法BFS# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None ...原创 2019-02-26 15:42:25 · 376 阅读 · 0 评论 -
LeetCode47. 全排列 II:(DFS) + (import itertools)
LeetCode47. 全排列 II:(DFS) + (import itertools)class Solution: def __init__(self): self.n = None self.v = None self.tmp = () self.tmp_ans = [] def permuteUnique...原创 2019-02-26 00:36:03 · 152 阅读 · 0 评论 -
LeetCode46. 全排列 两种方法:(DFS) + (import itertools)
LeetCode46. 全排列(DFS)class Solution: def __init__(self): self.v = None self.n = None self.tmp = [] self.ans = [] def permute(self, nums): self.n = len(...原创 2019-02-25 23:53:54 · 281 阅读 · 0 评论 -
LeetCode1 两数之和(字典法)
LeetCode1 两数之和(字典法)class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: m = {} for idx, x in enumerate(nums): y = target - x if ...原创 2019-02-25 21:57:18 · 247 阅读 · 0 评论 -
LeetCode513 找树左下角的值(BFS)
LeetCode513 找树左下角的值(BFS)BFS算法层层遍历,记录每层的最左边的结点的值# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = No...原创 2019-02-25 21:16:47 · 129 阅读 · 0 评论 -
LeetCode101. 对称二叉树 (递归) + (迭代)
LeetCode101. 对称二叉树 (递归) + (迭代)递归class Solution: def isSymmetric(self, root): """ :type root: TreeNode :rtype: bool """ if root: return sel...原创 2019-03-01 17:12:11 · 456 阅读 · 0 评论 -
LeetCode104 二叉树的最大深度(DFS)
LeetCode104 二叉树的最大深度(DFS)DFS递归# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solutio...原创 2019-02-25 17:47:19 · 204 阅读 · 0 评论 -
LeetCode337. 打家劫舍 III(DFS记忆化搜索)
LeetCode337. 打家劫舍 III(DFS记忆化搜索)# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solution:...原创 2019-03-24 18:55:40 · 294 阅读 · 0 评论