- 博客(27)
- 收藏
- 关注
原创 Leetcode 双周赛 48
竞赛地址T1第一题保存数字然后排序还要多说什么么?class Solution: def secondHighest(self, s: str) -> int: res = [] for ch in s: if ch.isdigit(): res.append(int(ch)) res = list(set(res)) if len(res) <= 1:
2021-03-21 20:49:03
260
原创 Leetcode 双周赛 47
竞赛地址T1T1有什么好说的么(class Solution: def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int: res = float('inf') cnt = -1 for k, (i, j) in enumerate(points): if i == x or j == y:
2021-03-07 14:05:51
229
原创 Leetcode 周赛 222
T1直接排序计算class Solution: def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int: boxTypes.sort(key = lambda x:x[1]) ans = 0 while truckSize and boxTypes: ni, nu = boxTypes.pop() if t
2021-01-03 16:18:09
337
3
原创 Leetcode 周赛 221 思路
竞赛地址T1直接模拟计数class Solution: def halvesAreAlike(self, s: str) -> bool: cnt = 0 for i in range(len(s) // 2): if s[i] in 'aeiouAEIOU': cnt += 1 if s[len(s) - i - 1] in 'aeiouAEIOU':
2020-12-27 18:31:22
255
5
原创 Leetcode 周赛 217 思路
写在前面:这一期我没有打,这是事后补做的,参考有。5613. 最富有客户的资产总量直接求和返回maxclass Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(sum(ni) for ni in accounts)5614. 找出最具竞争力的子序列单调栈,等效于删除len(nums)-k个以后最小class Solution: def mostC
2020-11-29 15:35:58
95
原创 Leetcode 双周赛 40 题解
竞赛地址5557. 最大重复子字符串直接贪心,暴力求解即可class Solution: def maxRepeating(self, sequence: str, word: str) -> int: for k in range(len(sequence)//len(word)+1,-1,-1): if k*word in sequence: return k5558. 合并两个链表这也有啥好说的,直接模拟
2020-11-29 00:00:40
168
原创 Leetcode 周赛 214 题解
https://leetcode-cn.com/contest/weekly-contest-214/竞赛地址5561. 获取生成数组中的最大值没啥好说的,直接模拟就好了class Solution: def getMaximumGenerated(self, n: int) -> int: if not n: return 0 nums=[0,1] for i in range(2,n+1):
2020-11-08 12:10:18
850
原创 Leetcode 双周赛 33
直接模拟 没啥问题class Solution: def thousandSeparator(self, n: int) -> str: if not n: return '0' ans='' i=0 while n : ans=str(n%10)+ans i+=1 if i%3==0: ans='..
2020-08-23 00:25:59
155
原创 求局域最小值的方法 学习笔记(2)
拟牛顿法的提出以及拟牛顿条件虽然牛顿法具有最速下降法所无法匹敌的下降的速度,但是有着几个非常明显的缺陷:1. 若Hessian矩阵不是正定矩阵,则会出现搜索方向可能不是函数的下降方向,使得函数不降反升。2. 若函数不存在二阶连续导数,则无法使用牛顿法求解3. 计算Hessian矩阵较为繁琐在此基础上,人们提出了拟牛顿法,核心思想与牛顿法相似...
2020-08-07 00:37:20
228
原创 Leetcode 周赛 199
重新排列字符串注意不是交换,只是插入一开始写成交换结果WA了一下class Solution: def restoreString(self, s: str, indices: List[int]) -> str: ans=['*' for _ in range( len(s))] for i,ni in enumerate(indices): ans[ni]=s[i] return ''.join(ans)灯
2020-07-27 14:24:07
139
原创 求局域最小值的方法 学习笔记
在之前的leetcode周赛里有这么一题,要求求平面上某点,到各个给定点的欧几里得距离之和最小,即求给定函数f(x,y)=∑i=1n(x−xi)2+(y−yi)2f(x,y)=\sum_{i=1}^n\sqrt{(x-x_i)^2+(y-y_i)^2}f(x,y)=∑i=1n(x−xi)2+(y−yi)2在平面上的最小值。频道里的大佬说了能直接调包来做,查了一下,python有scipy的optimize库可以用不同的算法来求解函数局域最小值。好的,非常感谢你的什么也没讲。那么就从这些缩写开始出
2020-07-23 17:56:33
498
原创 Leetcode weekly 198
换酒问题原题链接没啥好说的,直接模拟就行,停止循环的条件就是没有酒了class Solution: def numWaterBottles(self, numBottles: int, numExchange: int) -> int: remain=0 #换酒之后还有多少空瓶 ans=0 #答案 while numBottles: ans+=numBottles numBottles,re
2020-07-19 23:06:59
150
原创 Leetcode 周赛 195
'''按照编号模拟即可用set查重'''class Solution: def isPathCrossing(self, path: str) -> bool: x,y=0,0 visited=set() visited.add((x,y)) for ch in path: if ch=='N': y+=1 elif ch=='S': .
2020-06-28 15:01:30
127
原创 Leetcode 双周赛 29
'''快的可以一遍遍历取最大最小求和写的快一点可以直接调用函数'''class Solution: def average(self, salary: List[int]) -> float: return (sum(salary)-min(salary)-max(salary))/(len(salary)-2)'''还是可以考虑用其他快速方法得到N的因子列表可是可以暴力为什么不暴力呢1 <= k <= n <= 1000毕竟n这么小.
2020-06-28 00:05:07
130
原创 Leetcode 周赛 194
https://leetcode-cn.com/contest/weekly-contest-85/矩形重叠新21点多米诺骨牌(受力分析法)单词相似
2020-06-26 16:01:56
297
原创 Language interpolation and Aitken interpolation
两种插值方法(拉格朗日法和艾特肯法)先复制一段wiki上对插值的描述:数学的数值分析领域中,内插或称插值(英语:interpolation)是一种通过已知的、离散的数据点,在范围内推求新数据点的过程或方法。本文以多项式内插值为主,介绍拉格朗日法和艾特肯法构造内插函数。内插原理由Taylor展开,有f(x)=∑i=0inf(f(i)(x0)(x−x0)ii!)f(x)=\sum_{i=0}^{inf}(f^{(i)}(x_0)\frac{(x-x_0)^i}{i!})f(x)=∑i=0inf(f(i
2020-06-22 22:00:27
382
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人