deamn
deamn
全部文章
题解
归档
标签
去牛客网
登录
/
注册
deamn的博客
全部文章
/ 题解
(共9篇)
题解 | #接雨水问题#
利用双指针优化了动态规划问题,优化了空间复杂度o(n)->o(1) # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # max water # @param arr int整型一维数组 the array # @return long长整型 # class...
Python3
2022-05-09
0
308
题解 | #盛水最多的容器#
优化过的双指针 class Solution: def maxArea(self, height: List[int]) -> int: if not height: return 0 res = 0 left =...
Python3
2022-05-09
1
330
题解 | #买卖股票的最好时机(三)#
对于股票问题我们只需要得到所有的状态转移方程即可 由于题目要求只能交易两次 我们可以得到buy1,即第一次购买股票,sell1,第一次出售股票,buy2,第一次交易完成后第二次购买股票,sell2,第二次出售股票 class Solution: def maxProfit(self , pr...
Python3
2022-05-06
15
455
题解 | #最长公共子串#
采用了滑动窗口 left作为左指针,i作为右指针,不断更新窗口,如果1窗口中的字符串出现在2中,则右指针向右移,不然则左指针向右移, class Solution: def LCS(self , str1: str, str2: str) -> str: res="" ...
Python3
2022-05-05
4
408
题解 | #三数之和#
class Solution: def threeSum(self , num: List[int]) -> List[List[int]]: # write code here n=len(num) res=[] num...
Python3
2022-05-05
0
257
题解 | #打家劫舍(一)#
动态规划,优化了空间 class Solution: def rob(self , nums: List[int]) -> int: # write code here n=len(nums) if n==1: r...
Python3
2022-05-04
0
296
题解 | #兑换零钱(一)#
简单的动态规划思想 class Solution: def minMoney(self , coins: List[int], amount: int) -> int: dp=[float('inf')]*(amount+1) dp[0]=0 ...
Python3
2022-05-04
3
335
题解 | #三数之和#
采用双指针的方法,并进行排序保证没有重复 class Solution: def threeSum(self , num: List[int]) -> List[List[int]]: # write code here n=len(num) ...
Python3
2022-05-04
0
300
题解 | #三数之和#
class Solution: def threeSum(self , num: List[int]) -> List[List[int]]: # write code here num.sort() res=[] n=l...
Python3
2022-05-03
0
310