随笔分类 -  leetcode

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 22 下一页
摘要:题目描述: 自己的提交: class Solution: def minimumSwap(self, s1: str, s2: str) -> int: count = {"xy":0,"yx":0} for i in range(len(s1)): if s1[i] == s2[i]: conti 阅读全文
posted @ 2019-11-04 14:05 oldby 阅读(291) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交:超时: class Solution: def numberOfSubarrays(self, nums, k: int) -> int: dp = [0]* (len(nums)+1) res = 0 for i in range(len(nums)): if nums[i 阅读全文
posted @ 2019-11-04 13:57 oldby 阅读(132) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交:O(N) class Solution: def minRemoveToMakeValid(self, s: str) -> str: #from collections import Counter flag = [True] * len(s) stack = [] for 阅读全文
posted @ 2019-11-04 10:56 oldby 阅读(148) 评论(0) 推荐(0)
摘要:题目描述: 方法一:暴力O(MN) class Solution: def findSubstring(self, s: str, words: List[str]) -> List[int]: res = [] if not s or not words: return res for j in 阅读全文
posted @ 2019-10-31 15:27 oldby 阅读(144) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 class Solution: def f(self, n, m): if n < m: n, m = m, n if (n, m) in self.mem: return self.mem[(n, m)] if n == m: ans = 1 else: ans = 阅读全文
posted @ 2019-10-28 14:21 oldby 阅读(239) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交:O(2**n∗n∗m),m 为字符串长度 class Solution: def maxLength(self, arr: List[str]) -> int: from collections import Counter if not arr:return 0 res = 阅读全文
posted @ 2019-10-28 14:11 oldby 阅读(298) 评论(0) 推荐(0)
摘要:题目描述: 参考格雷编码: class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: res = [] for i in range(2 ** n): res.append((i >> 1) ^ i 阅读全文
posted @ 2019-10-28 10:08 oldby 阅读(163) 评论(0) 推荐(0)
摘要:题目描述: class Solution: def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[List[int]]: res = [] for i in range(1,1001): for j in r 阅读全文
posted @ 2019-10-28 10:01 oldby 阅读(168) 评论(0) 推荐(0)
摘要:题目描述: 方法:动态规划: 自底向上: class Solution: def minDistance(self, word1: str, word2: str) -> int: n = len(word1) m = len(word2) dp = [[0 for _ in range(n+1)] 阅读全文
posted @ 2019-10-26 16:44 oldby 阅读(111) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 一:超时 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 阅读(139) 评论(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 阅读(212) 评论(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 阅读(170) 评论(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 阅读(145) 评论(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 阅读(152) 评论(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 阅读(153) 评论(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 阅读(119) 评论(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 阅读(239) 评论(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 阅读(268) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def minAvailableDuration(self, slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]: res = [] i, 阅读全文
posted @ 2019-10-21 11:45 oldby 阅读(258) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def missingNumber(self, arr: List[int]) -> int: if len(arr) == 2: return arr[0] + (arr[1] - arr[0]) //2 if len(set(arr)) 阅读全文
posted @ 2019-10-21 11:29 oldby 阅读(201) 评论(0) 推荐(0)

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 22 下一页