随笔分类 -  leetcode

上一页 1 2 3 4 5 6 7 ··· 22 下一页
摘要:方法:动态规划 class Solution: def minDistance(self, houses: List[int], k: int) -> int: houses.sort() n = len(houses) cost = [[0]*n for _ in range(n)] for i 阅读全文
posted @ 2020-06-17 19:33 oldby 阅读(156) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def finalPrices(self, prices: List[int]) -> List[int]: res = [] for i in range(len(prices)): for j in range(i,len(prices)): 阅读全文
posted @ 2020-06-17 17:46 oldby 阅读(256) 评论(0) 推荐(0)
摘要:题目描述: 阅读全文
posted @ 2020-06-15 23:34 oldby 阅读(213) 评论(0) 推荐(0)
摘要:方法一:dp+前缀和 O(N) class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: n = len(arr) # dp[i]记录从第i个元素(包含第i个)往前找到的和为target最短子数组长度 阅读全文
posted @ 2020-06-15 10:42 oldby 阅读(266) 评论(0) 推荐(0)
摘要:题目描述: 解法一:二分法 提交:O(nlogn) class Solution: def findBestValue(self, arr: List[int], target: int) -> int: def helper(num): res = 0 for i in arr: if i > n 阅读全文
posted @ 2020-06-14 23:50 oldby 阅读(161) 评论(0) 推荐(0)
摘要:题目描述: class Solution: def minCost(self, houses: List[int], cost: List[List[int]], m: int, n: int, target: int) -> int: fcur = [[-1] * n for _ in range 阅读全文
posted @ 2020-06-11 11:10 oldby 阅读(228) 评论(0) 推荐(0)
摘要:题目描述: 提交: class BrowserHistory: def __init__(self, homepage: str): self.list = [homepage] self.cur = 0 def visit(self, url: str) -> None: if self.cur 阅读全文
posted @ 2020-06-11 10:51 oldby 阅读(179) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr = sorted(arr) m = arr[(len(arr) - 1) // 2] res = [] tmp = s 阅读全文
posted @ 2020-06-11 10:46 oldby 阅读(132) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: nums1 = nums[:n] nums2 = nums[n:] res = [] for i in range(n): res.a 阅读全文
posted @ 2020-06-11 10:41 oldby 阅读(158) 评论(0) 推荐(0)
摘要:题目描述: 方法一:O(N) O(N) class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: L = [1] * len(nums) R = [1] * len(nums) for i in range( 阅读全文
posted @ 2020-06-05 00:00 oldby 阅读(123) 评论(0) 推荐(0)
摘要:题目描述: 提价: class Solution: def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int: horizontalCuts.sort() vertical 阅读全文
posted @ 2020-06-01 10:30 oldby 阅读(177) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def minReorder(self, n: int, connections: List[List[int]]) -> int: connect = collections.defaultdict(set) c_set = set(tuple( 阅读全文
posted @ 2020-06-01 10:27 oldby 阅读(167) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def hasAllCodes(self, s: str, k: int) -> bool: k_list = set() if k > len(s): return False for i in range(len(s) - k + 1): if 阅读全文
posted @ 2020-06-01 10:13 oldby 阅读(124) 评论(0) 推荐(0)
摘要:题目描述: 方法:动态规划 自底向上: class Solution: def cherryPickup(self, A): R, C=len(A), len(A[0]) from functools import lru_cache @lru_cache(None) def dp(r,c1,c2) 阅读全文
posted @ 2020-06-01 10:06 oldby 阅读(233) 评论(0) 推荐(0)
摘要:题目描述: 提交:超时 class Solution: def checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]: dic = colle 阅读全文
posted @ 2020-06-01 09:23 oldby 阅读(183) 评论(0) 推荐(0)
摘要:方法一: 二分法 O(nlogn) O(1) class Solution { public int findDuplicate(int[] nums) { int len = nums.length; int left = 1; int right = len - 1; while(left < 阅读全文
posted @ 2020-05-26 23:03 oldby 阅读(232) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def maxDotProduct(self, nums1: List[int], nums2: List[int]) -> int: n1,n2 = len(nums1),len(nums2) dp = [[0] * n2 for _ in ra 阅读全文
posted @ 2020-05-25 10:54 oldby 阅读(207) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def pseudoPalindromicPaths (self, root: TreeNode) -> int: def helper(l,node): left,right = 0,0 if node.left == None and node 阅读全文
posted @ 2020-05-25 10:47 oldby 阅读(155) 评论(0) 推荐(0)
摘要:提交: class Solution: def maxVowels(self, s: str, k: int) -> int: n = len(s) dp = [0] * (n + 1) for i in range(n): if s[i] in "aeiou": dp[i + 1] = dp[i] 阅读全文
posted @ 2020-05-25 10:30 oldby 阅读(171) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: n = len(searchWord) sentence_l = sentence.split(" ") for i 阅读全文
posted @ 2020-05-25 10:20 oldby 阅读(197) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 22 下一页