随笔分类 - leetcode
摘要:方法: class Solution: def jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int: idx=[i for i in range(len(startTime))
阅读全文
摘要:题目描述: 方法: 另: class Solution: def balancedString(self, s: str) -> int: n, req = len(s), len(s) // 4 c_all = collections.Counter(s) c_cur = collections.
阅读全文
摘要:题目描述: 自己的提交: class Solution: def removeSubfolders(self, folder: List[str]) -> List[str]: d = {} res = [] for f in folder: l_f = f.split("/")[1:] node
阅读全文
摘要:自己的提交: class Solution: def checkStraightLine(self, coordinates: List[List[int]]) -> bool: if not coordinates: return False if len(coordinates) <= 2: r
阅读全文
摘要:题目描述: 方法一:动态规划 class Solution: def minCut(self, s: str) -> int: min_s = list(range(len(s))) n = len(s) dp = [[False] * n for _ in range(n)] for i in r
阅读全文
摘要:题目描述: class Solution: def findLadders(self, beginWord: str, endWord: str, wordList: list) -> list: wordList = set(wordList) # 转换为hash实现O(1)的in判断 if en
阅读全文
摘要:题目描述: 方法一:回溯 class Solution: def totalNQueens(self, n: int) -> int: def backtrack(i,tmp,col,z_diagonal,i_diagonal): if i == n: nonlocal res res += 1 r
阅读全文
摘要:题目描述: 第一次提交:回溯: class Solution: def solveNQueens(self, n: int) -> List[List[str]]: def sub(string, p, c): new = [s for s in string] new[p] = c return
阅读全文
摘要:题目描述: 回溯:超时 class Solution: def isMatch(self, s: str, p: str) -> bool: if not p: return not bool(s) if not s and p[0] == "*": return self.isMatch(s,p[
阅读全文
摘要:题目描述: 自己提交:未找出错(留坑) class Solution: def solveSudoku(self, board: List[List[str]]) -> None: def helper(i,j): if i==j==8: return True if i==8: print(i,j
阅读全文
摘要:题目描述: 回溯: 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]=="*": if s an
阅读全文
摘要:题目描述: 方法一:深度优先(官方题解) class Codec: def serialize(self, root): """Encodes a tree to a single string. :type root: TreeNode :rtype: str """ def rserialize
阅读全文
摘要:题目描述: 方法一:排序 O(nlogn) 超时 class MedianFinder: def __init__(self): """ initialize your data structure here. """ self.list = [] def addNum(self, num: int
阅读全文
摘要:题目描述: 方法:记录前一次的数值 class PeekingIterator: def __init__(self, iterator): """ Initialize your data structure here. :type iterator: Iterator """ self.iter
阅读全文
摘要:题目描述: 参考后提交:并查集: class Solution: def findRedundantDirectedConnection(self, edges: List[List[int]]) -> List[int]: def find(f,x): f.setdefault(x,x) if f
阅读全文
摘要:题目描述: 方法一:dfs() O(N**2) from collections import defaultdict class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: d
阅读全文
摘要:题目描述: 方法:欧拉回路 dfs class Solution: def findItinerary(self, tickets: List[List[str]]) -> List[str]: d = collections.defaultdict(list) for f,t in tickets
阅读全文
摘要:题目描述: 方法: class Solution(object): def maxEqualFreq(self, A): count = collections.Counter() freqs = collections.Counter() ans = 1 for i, x in enumerate
阅读全文
摘要:题目描述: 方法:动态规划O(6∗6∗n∗15) 递归: from functools import lru_cache class Solution: def dieSimulator(self, n, rollMax): MOD = 10 ** 9 + 7 @lru_cache(None) de
阅读全文
摘要:题目描述: 自己的提交: class Solution: def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]: if not queens:return [] res =
阅读全文
浙公网安备 33010602011771号