摘要: 题目描述: 方法一:动态规划 O(n^2) O(n) class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: maxlen=0 for word in wordDict: if len(word)>maxle 阅读全文
posted @ 2019-07-16 20:48 oldby 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:dfs O(N) O(N) class Solution: def copyRandomList(self, head: 'Node') -> 'Node': def dfs(head): if not head: return None if head in visited: 阅读全文
posted @ 2019-07-16 19:52 oldby 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:数学 class Solution: def singleNumber(self, nums: List[int]) -> int: return (sum(set(nums))*3 - sum(nums))//2 方法二: class Solution: def singleN 阅读全文
posted @ 2019-07-16 17:06 oldby 阅读(372) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:哈希表 O(N) O(N) class Solution: def singleNumber(self, nums: List[int]) -> int: hash_table = {} for i in nums: try: hash_table.pop(i) except: 阅读全文
posted @ 2019-07-16 16:30 oldby 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:O(n^2) (超时) class Solution: def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int: for i in range(len(gas)): if gas[i]-cost[i 阅读全文
posted @ 2019-07-16 16:18 oldby 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:dfs+hashmap """ # Definition for a Node. class Node: def __init__(self, val, neighbors): self.val = val self.neighbors = neighbors """ class 阅读全文
posted @ 2019-07-16 14:32 oldby 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交: class Solution: def partition(self, s: str) -> List[List[str]]: res = [] temp = [] def backtrack(s,temp): if not s: res.append(temp) for 阅读全文
posted @ 2019-07-16 13:41 oldby 阅读(308) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:dfs class Solution: def solve(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place instead. """ if not b 阅读全文
posted @ 2019-07-16 12:01 oldby 阅读(370) 评论(0) 推荐(0) 编辑