随笔分类 -  leetcode

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 22 下一页
摘要:方法: class Solution: def jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int: idx=[i for i in range(len(startTime)) 阅读全文
posted @ 2019-10-21 11:01 oldby 阅读(137) 评论(0) 推荐(0)
摘要:题目描述: 方法: 另: class Solution: def balancedString(self, s: str) -> int: n, req = len(s), len(s) // 4 c_all = collections.Counter(s) c_cur = collections. 阅读全文
posted @ 2019-10-21 09:56 oldby 阅读(312) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def removeSubfolders(self, folder: List[str]) -> List[str]: d = {} res = [] for f in folder: l_f = f.split("/")[1:] node 阅读全文
posted @ 2019-10-21 09:22 oldby 阅读(225) 评论(0) 推荐(0)
摘要:自己的提交: class Solution: def checkStraightLine(self, coordinates: List[List[int]]) -> bool: if not coordinates: return False if len(coordinates) <= 2: r 阅读全文
posted @ 2019-10-21 09:06 oldby 阅读(140) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 class Solution: def minCut(self, s: str) -> int: min_s = list(range(len(s))) n = len(s) dp = [[False] * n for _ in range(n)] for i in r 阅读全文
posted @ 2019-10-19 21:06 oldby 阅读(113) 评论(0) 推荐(0)
摘要:题目描述: class Solution: def findLadders(self, beginWord: str, endWord: str, wordList: list) -> list: wordList = set(wordList) # 转换为hash实现O(1)的in判断 if en 阅读全文
posted @ 2019-10-19 10:28 oldby 阅读(229) 评论(0) 推荐(0)
摘要:题目描述: 方法一:回溯 class Solution: def totalNQueens(self, n: int) -> int: def backtrack(i,tmp,col,z_diagonal,i_diagonal): if i == n: nonlocal res res += 1 r 阅读全文
posted @ 2019-10-18 19:52 oldby 阅读(142) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交:回溯: 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 阅读(124) 评论(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 阅读(154) 评论(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 阅读(409) 评论(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 阅读(192) 评论(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 阅读(138) 评论(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 阅读(160) 评论(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 阅读(225) 评论(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 阅读(206) 评论(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 阅读(299) 评论(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 阅读(313) 评论(0) 推荐(0)
摘要:题目描述: 方法: class Solution(object): def maxEqualFreq(self, A): count = collections.Counter() freqs = collections.Counter() ans = 1 for i, x in enumerate 阅读全文
posted @ 2019-10-14 10:46 oldby 阅读(182) 评论(0) 推荐(0)
摘要:题目描述: 方法:动态规划O(6∗6∗n∗15) 递归: from functools import lru_cache class Solution: def dieSimulator(self, n, rollMax): MOD = 10 ** 9 + 7 @lru_cache(None) de 阅读全文
posted @ 2019-10-14 10:03 oldby 阅读(242) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]: if not queens:return [] res = 阅读全文
posted @ 2019-10-14 08:59 oldby 阅读(158) 评论(0) 推荐(0)

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 22 下一页