上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 47 下一页
摘要: 题目描述: 方法一:动态规划 一:超时 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 阅读全文
posted @ 2019-10-26 14:39 oldby 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:动态规划+使用柱状图的优化暴力方法 O(N*2M) O(NM) N为行数 class Solution: def maximalRectangle(self, matrix: List[List[str]]) -> int: maxarea = 0 dp = [[0] * len 阅读全文
posted @ 2019-10-23 21:38 oldby 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:O(N) O(N) class Solution: def largestRectangleArea(self, heights: List[int]) -> int: if not heights: return 0 n = len(heights) left_i = [0] 阅读全文
posted @ 2019-10-23 13:41 oldby 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交: class Solution: def trap(self, height: List[int]) -> int: res = 0 def helper(height): nonlocal res if len(height) <= 1: return queue = [] 阅读全文
posted @ 2019-10-23 12:36 oldby 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 题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]=="* 阅读全文
posted @ 2019-10-22 18:10 oldby 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 二叉树的中序遍历: 迭代: 递归: 另: 二叉树的前序遍历: 递归: 迭代: 二叉树的后序遍历: 迭代1: 迭代2: 二叉树的层次遍历: 二叉树的锯齿形遍历: 递归: 迭代: 阅读全文
posted @ 2019-10-22 11:13 oldby 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交:超时 O(N**N) class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> List[str]: if not wordDict:return [] res = [] min_len,max_l 阅读全文
posted @ 2019-10-21 21:28 oldby 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 题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 阅读全文
posted @ 2019-10-21 19:50 oldby 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法: 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 阅读全文
posted @ 2019-10-21 14:01 oldby 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 二维dp: class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float: dp = [[0 for _ in range(target+1)] for _ in range(l 阅读全文
posted @ 2019-10-21 13:16 oldby 阅读(260) 评论(0) 推荐(0) 编辑
上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 47 下一页