摘要:
题目描述: 方法一:动态规划 一:超时 class Solution: def numSquares(self, n: int) -> int: dp = [float("inf")] * (n + 1) dp[0] = 0 for i in range(1, n + 1): for j in ra 阅读全文
摘要:
题目描述: 方法一:动态规划+使用柱状图的优化暴力方法 O(N*2M) O(NM) N为行数 class Solution: def maximalRectangle(self, matrix: List[List[str]]) -> int: maxarea = 0 dp = [[0] * len 阅读全文
摘要:
题目描述: 方法一:O(N) O(N) class Solution: def largestRectangleArea(self, heights: List[int]) -> int: if not heights: return 0 n = len(heights) left_i = [0] 阅读全文
摘要:
题目描述: 第一次提交: class Solution: def trap(self, height: List[int]) -> int: res = 0 def helper(height): nonlocal res if len(height) <= 1: return queue = [] 阅读全文
摘要:
题10: 回溯:另:动态规划复杂度更低 class Solution: def isMatch(self, s: str, p: str) -> bool: def helper(s,p): if not p: return not bool(s) if len(p)>=2 and p[1]=="* 阅读全文
摘要:
二叉树的中序遍历: 迭代: 递归: 另: 二叉树的前序遍历: 递归: 迭代: 二叉树的后序遍历: 迭代1: 迭代2: 二叉树的层次遍历: 二叉树的锯齿形遍历: 递归: 迭代: 阅读全文
摘要:
题目描述: 第一次提交:超时 O(N**N) class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> List[str]: if not wordDict:return [] res = [] min_len,max_l 阅读全文
摘要:
题77 回溯: class Solution: def combine(self, n: int, k: int) -> List[List[int]]: res = [] def backtrack(i,temp_list): if len(temp_list)==k: res.append(te 阅读全文
摘要:
题目描述: 方法: class Solution: def maximizeSweetness(self, A: List[int], K: int) -> int: def possible(x): k, temp = 0, 0 for a in A: temp += a if temp >= x 阅读全文
摘要:
题目描述: 二维dp: class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float: dp = [[0 for _ in range(target+1)] for _ in range(l 阅读全文