摘要: 方法一:dfs+图 class Solution: def calcEquation(self, equations: List[List[str]], values: List[float], queries: List[List[str]]) -> List[float]: graph = {} 阅读全文
posted @ 2019-10-11 20:31 oldby 阅读(230) 评论(0) 推荐(0) 编辑
摘要: - 题目:130 并查集: class Solution: def solve(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place instead. """ f = {} d 阅读全文
posted @ 2019-10-11 20:31 oldby 阅读(504) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:集合 O(N) class Solution: def longestConsecutive(self, nums: List[int]) -> int: nums = set(nums) res = 0 for num in nums: if num-1 not in nums 阅读全文
posted @ 2019-10-11 15:21 oldby 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:动态规划 O(Nk) class Solution: def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int: dp = [1] * n l = [0]*len(primes) for i in range(1 阅读全文
posted @ 2019-10-11 10:33 oldby 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:递归 class Solution: def isUgly(self, num: int) -> bool: if num == 0: return False if num == 1:return True if num % 2 == 0: return self.isUgly 阅读全文
posted @ 2019-10-11 10:01 oldby 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:堆 O(nlogn) class Solution: def nthUglyNumber(self, n: int) -> int: import heapq heap = [1] res = 0 heapq.heapify(heap) for _ in range(n): re 阅读全文
posted @ 2019-10-11 09:39 oldby 阅读(164) 评论(0) 推荐(0) 编辑