随笔分类 -  leetcode

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 22 下一页
摘要:题目描述: 自己的提交: class Solution: def isPossibleDivide(self, nums: List[int], k: int) -> bool: c = collections.Counter(nums) n = len(nums) m = n/k if m%1 ! 阅读全文
posted @ 2019-12-25 19:04 oldby 阅读(226) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: c = collections.Counter() for i in range(l 阅读全文
posted @ 2019-12-25 17:25 oldby 阅读(246) 评论(0) 推荐(0)
摘要:题目描述: 方法一:bfs class Solution: def maxCandies(self, status: List[int], candies: List[int], keys: List[List[int]], containedBoxes: List[List[int]], init 阅读全文
posted @ 2019-12-25 17:11 oldby 阅读(150) 评论(0) 推荐(0)
摘要:题目描述: 提交: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def getDec 阅读全文
posted @ 2019-12-24 14:35 oldby 阅读(192) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def sequentialDigits(self, low: int, high: int) -> List[int]: l,h = len(str(low)),len(str(high)) res = [] def helper(num, 阅读全文
posted @ 2019-12-24 14:30 oldby 阅读(247) 评论(0) 推荐(0)
摘要:题目描述; 自己的提交:超时 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 阅读全文
posted @ 2019-12-24 14:19 oldby 阅读(226) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交:广度优先 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 阅读全文
posted @ 2019-12-24 11:32 oldby 阅读(486) 评论(0) 推荐(0)
摘要:题目描述: 方法: class CombinationIterator: def __init__(self, characters: str, combinationLength: int): self.s = characters self.pos = [x for x in range(com 阅读全文
posted @ 2019-12-23 16:24 oldby 阅读(231) 评论(0) 推荐(0)
摘要:题目描述: 方法一:排序O(Nlogn) class Solution: def removeCoveredIntervals(self, intervals: List[List[int]]) -> int: intervals.sort(key = lambda x:(x[0],-x[1])) 阅读全文
posted @ 2019-12-23 16:03 oldby 阅读(155) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 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 阅读全文
posted @ 2019-12-23 15:40 oldby 阅读(201) 评论(0) 推荐(0)
摘要:题目描述: 方法一:暴力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) 阅读全文
posted @ 2019-12-09 14:59 oldby 阅读(258) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: ans = [] dic = {} for v,i in enumerate(groupSizes): i 阅读全文
posted @ 2019-12-09 10:37 oldby 阅读(219) 评论(0) 推荐(0)
摘要:题目描述: 方法一:O(MN) class Solution: def minWindow(self, s: 'str', t: 'str') -> 'str': from collections import Counter t = Counter(t) lookup = Counter() st 阅读全文
posted @ 2019-12-06 13:32 oldby 阅读(253) 评论(0) 推荐(0)
摘要:题目描述: 动态规划: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 + 阅读全文
posted @ 2019-12-02 20:24 oldby 阅读(141) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def countSquares(self, matrix: List[List[int]]) -> int: if not matrix: return 0 m,n = len(matrix),len(matrix[0]) dp = [0] 阅读全文
posted @ 2019-12-02 19:15 oldby 阅读(226) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]: t = (tomatoSlices - 2 * cheeseSlices) / 2 c = 阅读全文
posted @ 2019-12-02 18:27 oldby 阅读(144) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def tictactoe(self, moves: List[List[int]]) -> str: p = [[0] * 3 for _ in range(3)] if len(moves) < 5: return "Pending" f 阅读全文
posted @ 2019-12-02 18:24 oldby 阅读(274) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: # """ # This is Sea's API interface. # You should not implement it, or speculate about its implementation # """ #class Sea(object): # def 阅读全文
posted @ 2019-12-02 13:21 oldby 阅读(223) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: List[int]) -> int: dp = [[0, 0]for _ in range(nodes)] 阅读全文
posted @ 2019-12-02 12:42 oldby 阅读(320) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]: res = [] for i in interv 阅读全文
posted @ 2019-12-02 12:30 oldby 阅读(201) 评论(0) 推荐(0)

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 22 下一页