随笔分类 - leetcode
摘要:题目描述: 自己的提交: class Solution: def isPossibleDivide(self, nums: List[int], k: int) -> bool: c = collections.Counter(nums) n = len(nums) m = n/k if m%1 !
阅读全文
摘要:题目描述: 自己的提交: class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: c = collections.Counter() for i in range(l
阅读全文
摘要:题目描述: 方法一:bfs class Solution: def maxCandies(self, status: List[int], candies: List[int], keys: List[List[int]], containedBoxes: List[List[int]], init
阅读全文
摘要:题目描述: 提交: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def getDec
阅读全文
摘要:题目描述: 自己的提交: class Solution: def sequentialDigits(self, low: int, high: int) -> List[int]: l,h = len(str(low)),len(str(high)) res = [] def helper(num,
阅读全文
摘要:题目描述; 自己的提交:超时 class Solution: def maxSideLength(self, mat: List[List[int]], threshold: int) -> int: m,n = len(mat),len(mat[0]) res = 0 for i in range
阅读全文
摘要:题目描述: 自己的提交:广度优先 O(mn*min(k,m+n)) class Solution: def shortestPath(self, grid, k: int) -> int: visited = {} queue = [[0,0,k-1]]if grid[0][0] == 1 and
阅读全文
摘要:题目描述: 方法: class CombinationIterator: def __init__(self, characters: str, combinationLength: int): self.s = characters self.pos = [x for x in range(com
阅读全文
摘要:题目描述: 方法一:排序O(Nlogn) class Solution: def removeCoveredIntervals(self, intervals: List[List[int]]) -> int: intervals.sort(key = lambda x:(x[0],-x[1]))
阅读全文
摘要:题目描述: 方法一:动态规划 O(N^3) class Solution: def minFallingPathSum(self, arr: List[List[int]]) -> int: n = len(arr) for i in range(1,n): for j in range(n): a
阅读全文
摘要:题目描述: 方法一:暴力BFS class Solution: def minFlips(self, mat) -> int: R, C = len(mat), len(mat[0]) def helper(mat): return tuple(tuple(row) for row in mat)
阅读全文
摘要:题目描述: 自己的提交: class Solution: def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: ans = [] dic = {} for v,i in enumerate(groupSizes): i
阅读全文
摘要:题目描述: 方法一:O(MN) class Solution: def minWindow(self, s: 'str', t: 'str') -> 'str': from collections import Counter t = Counter(t) lookup = Counter() st
阅读全文
摘要:题目描述: 动态规划:O(N^3) class Solution: def palindromePartition(self, s: str, k: int) -> int: def cost(i, j): r = 0 while i < j: if s[i] != s[j]: r += 1 i +
阅读全文
摘要:题目描述: 自己的提交: class Solution: def countSquares(self, matrix: List[List[int]]) -> int: if not matrix: return 0 m,n = len(matrix),len(matrix[0]) dp = [0]
阅读全文
摘要:题目描述: 自己的提交: class Solution: def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]: t = (tomatoSlices - 2 * cheeseSlices) / 2 c =
阅读全文
摘要:题目描述: 自己的提交: class Solution: def tictactoe(self, moves: List[List[int]]) -> str: p = [[0] * 3 for _ in range(3)] if len(moves) < 5: return "Pending" f
阅读全文
摘要:题目描述: 自己的提交: # """ # This is Sea's API interface. # You should not implement it, or speculate about its implementation # """ #class Sea(object): # def
阅读全文
摘要:题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: List[int]) -> int: dp = [[0, 0]for _ in range(nodes)]
阅读全文
摘要:题目描述: 自己的提交: class Solution: def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]: res = [] for i in interv
阅读全文
浙公网安备 33010602011771号