zp

Results 6 comments of zp

你这方法简单易懂👍 附一个python完整代码: ```python class Solution(): def calculate(self,s: str) -> int: def f(s): num,sgn,st=0,'+',deque() while len(s)>0: c = s.pop(0) if c.isdigit(): num = 10*num + int(c) if c=='(': num = f(s)...

进一步思考了一下,原文中需要计算数值的判断条件 ```python if (not c.isdigit() and c != ' ') or len(s) == 0: ``` 如果改为 ```python if c in ['+','-','*','/',')'] or len(s)==0: ``` 思路会更清晰一些,只有在遇到 + - * / )...

起点升序排序,终点降序 然后只需要判断覆盖情况即可 ```python class Solution: def removeCoveredIntervals(self, s: List[List[int]]) -> int: n = len(s) s = sorted(s,key=lambda k:(k[0],-k[1])) a = s[0] res = 0 for i in range(1,n): b =...

提供一个简单版本: 主要递推式:f(l,r)=max(s[l]-f(l+1,r),s[r]-f(l,r-1)) 代表石头[l,r]区间内我的最大相对收益是多少 最后f(0,n-1)>0即为答案 ```python class Solution: def stoneGame(self, s: List[int]) -> bool: n = len(s) vstd = [[-1]*(n+1) for _ in range(n+1)] def f(l,r): if vstd[l][r]!=-1: return vstd[l][r] if...

493 翻转对题目中 对merge函数的改造代码里: // 在合并有序数组之前,加点私货 for (int i = lo; i (long)nums[j] * 2) 应改为:if ((long)nums[i] > (long)nums[j] * 2)

@maqiang515 https://huggingface.co/datasets/kwaikeg/KAgentInstruct