Alwin4Zhang

Results 39 comments of Alwin4Zhang

爱吃香蕉的珂珂 python version ```py import math class Solution: def minEatingSpeed(self, piles: List[int], h: int) -> int: # 问题转化,搜索区间是[1,max_piles] # nums[mid]用于计算以当前的速度吃完香蕉的时间是多少小时 # 需要求满足条件的最小speed,实际上就是左边界问题,因为不同的速度消耗时间是相同的 def f(piles, speed): hours = 0 for pile...

1011. 在D天内送达包裹的能力(中等) ```py # @lc code=start class Solution: def shipWithinDays(self, weights: List[int], days: int) -> int: def f(weights, capacity): cur = 0 days = 0 for i, weight in enumerate(weights):...

743. 网络延迟时间(中等) python version ```py import collections import heapq class State(object): def __init__(self, id, dist_from_start): self.id = id self.dist_from_start = dist_from_start def __lt__(self, other): if self.dist_from_start < other.dist_from_start: return True...

1631 题「 最小体力消耗路径」python version ```py import collections import heapq class State(object): def __init__(self, x, y, effort_from_start): self.x = x self.y = y self.effort_from_start = effort_from_start def __lt__(self, other): return self.effort_from_start...

1514 题「 概率最大的路径」 python version ```py import heapq import collections class State(object): def __init__(self, id, prob_from_start): self.id = id self.prob_from_start = prob_from_start def __lt__(self, other): # 大顶堆 return self.prob_from_start >...

1135 题「 最低成本联通所有城市」,Prim算法的python实现 ```py import heapq import collections class Solution: # Kruscal并查集方式判定 class UnionFind(object): def __init__(self, n): self.parent = list(range(n)) def find(self, x): while self.parent[x] != x: self.parent[x] = self.parent[self.parent[x]]...

### 45. 跳跃游戏 II python versions dp动态规划 勉强通过,没有超时 ```py class Solution: def jump(self, nums: List[int]) -> int: n = len(nums) dp = [0] * n # dp[i]表示从开头0位置到当前i的最小步数 for i in...

921 题「 使括号有效的最少添加」:Python version 只需要在20题【有效的括号】的基础上稍作改动,有其他括号的暂时忽略 ```py class Solution: def minAddToMakeValid(self, s: str) -> int: def leftof(c): if c == '}': return '{' elif c == ')': return '(' return '['...

patience_sort(耐心排序) python verisons ```py # 比较直观的方式 def lis(nums): stack = [[]] for v in nums: for s in stack: if not s or s[-1] >= v: s.append(v) break else: #...

是不是也可以通过将中点左侧或者右侧的链表翻转,然后双指针分别从头遍历2个链表判断是不是相同链表?