07 2020 档案
摘要:题目描述: 方法一:双指针 O(N+M) O(1) class Solution: def isSubsequence(self, s: str, t: str) -> bool: if s == "" and t == "": return True if t == "": return Fals
阅读全文
摘要:题目描述: 方法一:动态规划 O(mnlogmn) class Solution(object): def longestIncreasingPath(self, matrix): if not matrix or not matrix[0]: return 0 m, n = len(matrix)
阅读全文
摘要:题目描述: 方法:二分法 O(N*log(summ - maxn)) class Solution: def splitArray(self, nums: List[int], m: int) -> int: n = len(nums) s = 0 for num in nums: s += num
阅读全文
摘要:题目描述: 官方解答: 方法一:记忆化递归 O(N3) O(N2) class Solution: def maxCoins(self, nums: List[int]) -> int: n = len(nums) val = [1] + nums + [1] @lru_cache(None) de
阅读全文
摘要:恢复内容开始 题目描述: 方法一:边统计边压缩: class Solution { public int numSubmat(int[][] mat) { int row = mat.length, col = mat[0].length, ans = 0; for (int i = 0; i <
阅读全文
摘要:题目描述: 第一次提交:通过76/78 留坑 class Solution: def isBipartite(self, graph: List[List[int]]) -> bool: dic = {} l = [] for i in range(len(graph)): if graph[i]
阅读全文
摘要:题目描述: 方法:动态规划 class Solution: def winnerSquareGame(self, n: int) -> bool: dp = [False, True, False] for x in range(3, n+1): dp.append(False) for y in
阅读全文
摘要:题目描述: 提交: class Solution: def minDifference(self, nums: List[int]) -> int: if len(nums) <= 4: return 0 minm = min(nums) maxm = max(nums) l1 = heapq.nl
阅读全文
摘要:题目描述: 提交:O(m+n) class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: nums2dic = collections.Counter(nums2) res = [] f
阅读全文
摘要:题目描述: 方法一:动态规划 O(mn) O(mn) class Solution: def calculateMinimumHP(self, dungeon: List[List[int]]) -> int: rows = len(dungeon) cols = len(dungeon[0]) d
阅读全文
摘要:题目描述: 提交:堆 class Solution: def minDifference(self, nums: List[int]) -> int: if len(nums) <= 4: return 0 minm = min(nums) maxm = max(nums) l1 = heapq.n
阅读全文
摘要:题目描述: 方法一:二分 时间复杂度应该是O(n2) class Solution: def countSmaller(self, nums: List[int]) -> List[int]: num_length = len(nums) if not nums: return [] res = [
阅读全文
摘要:题目描述: 提交: class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: l = [] for i in range(n): for j in range(i+1,n+1)
阅读全文
摘要:题目描述: 提交: class Solution: def reformatDate(self, date: str) -> str: l = date.split(" ") d = l[0][:-2] ml = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
阅读全文
摘要:题目描述: 方法一:动态规划 O(n) O(n) class Solution: def maxProfit(self, prices: List[int]) -> int: if len(prices) < 2: return 0 n = len(prices) sell = [0] * n bu
阅读全文
摘要:题目描述: 方法一:动态规划 O(n2) ->O(mn) m为字典中单词最大长度 class Solution: def respace(self, dictionary: List[str], sentence: str) -> int: d = {}.fromkeys(dictionary) n
阅读全文
摘要:题目描述: 方法一:纯volatile实现 class FizzBuzz { private int n; private volatile int f = 0; private volatile int b = 0; private volatile int fb = 0; private vol
阅读全文
摘要:题目描述: 提交:O(n) class Solution: def divingBoard(self, shorter: int, longer: int, k: int) -> List[int]: if k == 0: return [] res = [] for i in range(k,-1
阅读全文
摘要:题目描述: 方法一:动态规划 O(n) O(n) class Solution: def longestValidParentheses(self, s: str) -> int: n = len(s) if n==0:return 0 dp = [0]*n for i in range(len(s
阅读全文
摘要:题目描述: 方法一:动态规划 O(mn) O(mn) class Solution: def findLength(self, A: List[int], B: List[int]) -> int: n, m = len(A), len(B) dp = [[0] * (m + 1) for _ in
阅读全文
摘要:题目描述: 方法:动态规划+状态压缩 class Solution: def minNumberOfSemesters(self, n: int, dependencies: List[List[int]], k: int) -> int: dep = {} # 记录依赖于某节点的节点列表 for
阅读全文
浙公网安备 33010602011771号