上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 47 下一页
摘要: 题目描述: 第一次提交:回溯: class Solution: def solveNQueens(self, n: int) -> List[List[str]]: def sub(string, p, c): new = [s for s in string] new[p] = c return 阅读全文
posted @ 2019-10-18 12:52 oldby 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 回溯:超时 class Solution: def isMatch(self, s: str, p: str) -> bool: if not p: return not bool(s) if not s and p[0] == "*": return self.isMatch(s,p[ 阅读全文
posted @ 2019-10-18 10:43 oldby 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己提交:未找出错(留坑) class Solution: def solveSudoku(self, board: List[List[str]]) -> None: def helper(i,j): if i==j==8: return True if i==8: print(i,j 阅读全文
posted @ 2019-10-18 09:21 oldby 阅读(396) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 回溯: class Solution: def isMatch(self, s: str, p: str) -> bool: def helper(s,p): if not p: return not bool(s) if len(p)>=2 and p[1]=="*": if s an 阅读全文
posted @ 2019-10-17 19:06 oldby 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:深度优先(官方题解) class Codec: def serialize(self, root): """Encodes a tree to a single string. :type root: TreeNode :rtype: str """ def rserialize 阅读全文
posted @ 2019-10-16 20:27 oldby 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:排序 O(nlogn) 超时 class MedianFinder: def __init__(self): """ initialize your data structure here. """ self.list = [] def addNum(self, num: int 阅读全文
posted @ 2019-10-16 16:17 oldby 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法:记录前一次的数值 class PeekingIterator: def __init__(self, iterator): """ Initialize your data structure here. :type iterator: Iterator """ self.iter 阅读全文
posted @ 2019-10-16 11:10 oldby 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 参考后提交:并查集: class Solution: def findRedundantDirectedConnection(self, edges: List[List[int]]) -> List[int]: def find(f,x): f.setdefault(x,x) if f 阅读全文
posted @ 2019-10-15 11:46 oldby 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:dfs() O(N**2) from collections import defaultdict class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: d 阅读全文
posted @ 2019-10-15 09:52 oldby 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法:欧拉回路 dfs class Solution: def findItinerary(self, tickets: List[List[str]]) -> List[str]: d = collections.defaultdict(list) for f,t in tickets 阅读全文
posted @ 2019-10-14 19:55 oldby 阅读(307) 评论(0) 推荐(0) 编辑
上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 47 下一页