摘要:
暴搜的话,在k大的时候是O(n**2)的复杂度,会超时. 采用一个字典来记录每个value的位置.O(N) 阅读全文
摘要:
把pattern映射到数字,也就是把pattern标准化. 比如abb和cdd如果都能标准化为011,那么就是同构的. 阅读全文
摘要:
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None import functools @functools.lru_cach... 阅读全文
摘要:
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None import functools class Solution: ... 阅读全文
摘要:
class Solution: def numRookCaptures(self, board: List[List[str]]) -> int: rook = [0, 0] ans = 0 for i in range(8): for j in range(8): if board[... 阅读全文
摘要:
class Solution: def arrayPairSum(self, nums: List[int]) -> int: nums.sort() ans, i = 0, 0 while i < len(nums): ans += nums[i] i += 2 return... 阅读全文
摘要:
class Solution: def peakIndexInMountainArray(self, A: List[int]) -> int: for i in range(1,len(A)-1): if A[i-1]A[i+1]: return i 阅读全文
摘要:
class Solution: def selfDividingNumbers(self, left: int, right: int) -> List[int]: ans = [] for i in range(left, right+1): if self.decide(i): ans.appen... 阅读全文
摘要:
class Solution: def minDeletionSize(self, A: List[str]) -> int: ans = 0 for j in range(len(A[0])): t = [] for a in A: t.append(a[j]) ... 阅读全文
摘要:
如果是'I'就加入当前最小的,是'D'就加入当前最大的. 阅读全文