摘要: 题目描述: 提交: class Solution: def maxLengthBetweenEqualCharacters(self, s: str) -> int: dic = {} res = -1 for i,v in enumerate(s): if v not in dic: dic[v] 阅读全文
posted @ 2020-10-18 12:18 oldby 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 方法一: INF = 1 << 60 class Solution: def minSubarray(self, A: List[int], p: int) -> int: idx = {} n = len(A) S = [0] * (n + 1) for i in range(n): S[i + 阅读全文
posted @ 2020-09-22 12:25 oldby 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法:记录request的开头结尾 from typing import List class Solution: def maxSumRangeQuery(self, nums: List[int], requests: List[List[int]]) -> int: n = len 阅读全文
posted @ 2020-09-20 14:26 oldby 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 题目描述: dfs: class Solution: def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]: initColor = image[sr][sc] 阅读全文
posted @ 2020-08-17 22:34 oldby 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 提交: class Solution: def countBinarySubstrings(self, s: str) -> int: if not s: return 0 res = 0 count = [0,0] for i in range(len(s)): num = int(s 阅读全文
posted @ 2020-08-11 00:02 oldby 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:双指针 O(N) O(1) class Solution: def getWinner(self, arr: List[int], k: int) -> int: strike = 0 cur, i = 0, 1 while i < len(arr): if arr[i] < a 阅读全文
posted @ 2020-08-04 23:35 oldby 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:排序滑窗 class Solution: def smallestRange(self, nums: List[List[int]]) -> List[int]: lst = [] for i in range(len(nums)): for j in range(len(num 阅读全文
posted @ 2020-08-03 19:28 oldby 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:数学 O(1) O(1) class Solution: def integerBreak(self, n: int) -> int: if n <= 3: return n - 1 a, b = n // 3, n % 3 if b == 0: return int(math. 阅读全文
posted @ 2020-08-01 09:27 oldby 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 方法:后序遍历 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left 阅读全文
posted @ 2020-08-01 09:15 oldby 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:双指针 O(N+M) O(1) class Solution: def isSubsequence(self, s: str, t: str) -> bool: if s == "" and t == "": return True if t == "": return Fals 阅读全文
posted @ 2020-07-28 21:41 oldby 阅读(161) 评论(0) 推荐(0) 编辑