摘要:
题目描述: 方法一:原地哈希 class Solution: def firstMissingPositive(self, nums: List[int]) -> int: n = len(nums) for i in range(n): if nums[i] <= 0: nums[i] = n + 阅读全文
摘要:
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def removeDuplicateN 阅读全文
摘要:
题目描述: 提交: class Solution: from typing import List def avoidFlood(self, rains: List[int]) -> List[int]: import heapq heap = [] res = [-1 if i != 0 else 阅读全文
摘要:
题目描述: 第一次提交: 有错 未找出问题 留坑 class Solution: def getFolderNames(self, names: List[str]) -> List[str]: res = [] dic = collections.Counter() for name in nam 阅读全文
摘要:
方法一: class Solution: def patternMatching(self, pattern: str, value: str) -> bool: count_a = sum(1 for ch in pattern if ch == 'a') count_b = len(patter 阅读全文
摘要:
方法:递归 O(n) O(n) class Solution: def __init__(self): self.maxSum = float("-inf") def maxPathSum(self, root: TreeNode) -> int: def maxGain(node): if not 阅读全文
摘要:
提交: class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: count = collections.Counter(arr) order_dic = sorted(count.items 阅读全文
摘要:
方法:倍增法dp ACM经典 class TreeAncestor: def __init__(self, n: int, parent: List[int]): self.cols = 20 # log(50000) < 20 self.dp = [[-1] * self.cols for _ i 阅读全文
摘要:
方法:迭代+栈 O(N) class Solution { public TreeNode recoverFromPreorder(String S) { Deque<TreeNode> path = new LinkedList<>(); int pos = 0; while(pos < S.le 阅读全文
摘要:
解:O(N) class Solution: def maxScoreSightseeingPair(self, A: List[int]) -> int: left, res = A[0], -1 for j in range(1, len(A)): res = max(res, left + A 阅读全文