上一页 1 2 3 4 5 6 7 8 ··· 47 下一页
摘要: 题目描述: 方法一:原地哈希 class Solution: def firstMissingPositive(self, nums: List[int]) -> int: n = len(nums) for i in range(n): if nums[i] <= 0: nums[i] = n + 阅读全文
posted @ 2020-06-27 21:47 oldby 阅读(139) 评论(0) 推荐(0) 编辑
摘要: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def removeDuplicateN 阅读全文
posted @ 2020-06-26 23:47 oldby 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 提交: class Solution: from typing import List def avoidFlood(self, rains: List[int]) -> List[int]: import heapq heap = [] res = [-1 if i != 0 else 阅读全文
posted @ 2020-06-26 09:45 oldby 阅读(386) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交: 有错 未找出问题 留坑 class Solution: def getFolderNames(self, names: List[str]) -> List[str]: res = [] dic = collections.Counter() for name in nam 阅读全文
posted @ 2020-06-25 09:29 oldby 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 方法一: 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 阅读全文
posted @ 2020-06-22 23:38 oldby 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 方法:递归 O(n) O(n) class Solution: def __init__(self): self.maxSum = float("-inf") def maxPathSum(self, root: TreeNode) -> int: def maxGain(node): if not 阅读全文
posted @ 2020-06-22 00:03 oldby 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 提交: class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: count = collections.Counter(arr) order_dic = sorted(count.items 阅读全文
posted @ 2020-06-19 22:37 oldby 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 方法:倍增法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 阅读全文
posted @ 2020-06-19 22:36 oldby 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 方法:迭代+栈 O(N) class Solution { public TreeNode recoverFromPreorder(String S) { Deque<TreeNode> path = new LinkedList<>(); int pos = 0; while(pos < S.le 阅读全文
posted @ 2020-06-19 00:07 oldby 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 解: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 阅读全文
posted @ 2020-06-17 23:48 oldby 阅读(133) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 47 下一页