上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 47 下一页
摘要: 题目描述: 方法一: class FindElements: def __init__(self, root: TreeNode): self.d = set() def f(r, x): if r: self.d.add(x) r.val = x f(r.left, 2 * x + 1) f(r. 阅读全文
posted @ 2019-11-20 11:24 oldby 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交: class Solution: def shiftGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: m,n = len(grid),len(grid[0]) while k: tmp = [[0] * 阅读全文
posted @ 2019-11-20 11:16 oldby 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法:穷举暴力 class Solution: def maxScoreWords(self, words: List[str], letters: List[str], score: List[int]) -> int: from collections import Counter 阅读全文
posted @ 2019-11-11 17:04 oldby 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交: class Solution: def closedIsland(self, grid: List[List[int]]) -> int: def dfs(grid,r,c): nr = len(grid) nc = len(grid[0]) if r<0 or c<0 o 阅读全文
posted @ 2019-11-11 16:18 oldby 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交: class Solution: def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) -> List[List[int]]: res = [[],[]] for v,i in enume 阅读全文
posted @ 2019-11-11 15:59 oldby 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交: class Solution: def oddCells(self, n: int, m: int, indices: List[List[int]]) -> int: nums = [[0] * m for _ in range(n)] for i,j in indice 阅读全文
posted @ 2019-11-11 15:47 oldby 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法:区间dp O(N^3) class Solution: def minimumMoves(self, A: List[int]) -> int: N = len(A) dp = [[0] * (N+1) for _ in range(N+1)] for i in range(N+1 阅读全文
posted @ 2019-11-05 14:40 oldby 阅读(687) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:深度优先: class Solution: def treeDiameter(self, edges: List[List[int]]) -> int: adjacency = collections.defaultdict(set) for i,j in edges: adja 阅读全文
posted @ 2019-11-05 13:48 oldby 阅读(304) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交: class Solution: def transformArray(self, arr: List[int]) -> List[int]: if len(arr) < 3: return arr flag = True while flag: tmp = [] tmp.a 阅读全文
posted @ 2019-11-05 12:33 oldby 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 题目描述: class Leaderboard: def __init__(self): self.map = collections.Counter() def addScore(self, playerId: int, score: int) -> None: self.map[playerId 阅读全文
posted @ 2019-11-05 11:48 oldby 阅读(287) 评论(0) 推荐(0) 编辑
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 47 下一页