随笔分类 -  leetcode

上一页 1 2 3 4 5 6 ··· 22 下一页
摘要:题目描述: 方法一:二分 时间复杂度应该是O(n2) class Solution: def countSmaller(self, nums: List[int]) -> List[int]: num_length = len(nums) if not nums: return [] res = [ 阅读全文
posted @ 2020-07-12 22:29 oldby 阅读(136) 评论(0) 推荐(0)
摘要:题目描述: 提交: class Solution: def reformatDate(self, date: str) -> str: l = date.split(" ") d = l[0][:-2] ml = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", 阅读全文
posted @ 2020-07-12 10:20 oldby 阅读(185) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 O(n) O(n) class Solution: def maxProfit(self, prices: List[int]) -> int: if len(prices) < 2: return 0 n = len(prices) sell = [0] * n bu 阅读全文
posted @ 2020-07-11 21:06 oldby 阅读(163) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 O(n2) ->O(mn) m为字典中单词最大长度 class Solution: def respace(self, dictionary: List[str], sentence: str) -> int: d = {}.fromkeys(dictionary) n 阅读全文
posted @ 2020-07-10 08:51 oldby 阅读(130) 评论(0) 推荐(0)
摘要:题目描述: 方法一:纯volatile实现 class FizzBuzz { private int n; private volatile int f = 0; private volatile int b = 0; private volatile int fb = 0; private vol 阅读全文
posted @ 2020-07-08 23:22 oldby 阅读(259) 评论(0) 推荐(0)
摘要:题目描述: 提交:O(n) class Solution: def divingBoard(self, shorter: int, longer: int, k: int) -> List[int]: if k == 0: return [] res = [] for i in range(k,-1 阅读全文
posted @ 2020-07-08 22:37 oldby 阅读(115) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 O(n) O(n) class Solution: def longestValidParentheses(self, s: str) -> int: n = len(s) if n==0:return 0 dp = [0]*n for i in range(len(s 阅读全文
posted @ 2020-07-04 23:13 oldby 阅读(123) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 O(mn) O(mn) class Solution: def findLength(self, A: List[int], B: List[int]) -> int: n, m = len(A), len(B) dp = [[0] * (m + 1) for _ in 阅读全文
posted @ 2020-07-01 22:28 oldby 阅读(254) 评论(0) 推荐(0)
摘要:题目描述: 方法:动态规划+状态压缩 class Solution: def minNumberOfSemesters(self, n: int, dependencies: List[List[int]], k: int) -> int: dep = {} # 记录依赖于某节点的节点列表 for 阅读全文
posted @ 2020-07-01 08:56 oldby 阅读(486) 评论(0) 推荐(0)
摘要:题目描述: 方法一:原地哈希 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 阅读(145) 评论(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 阅读(88) 评论(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 阅读(404) 评论(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 阅读(175) 评论(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 阅读(201) 评论(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 阅读(58) 评论(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 阅读(223) 评论(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 阅读(279) 评论(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 阅读(133) 评论(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 阅读(141) 评论(0) 推荐(0)
摘要:题目描述: 提交:二分 O(nlogk) class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: minday = min(bloomDay) maxday = max(bloomDay) def 阅读全文
posted @ 2020-06-17 20:20 oldby 阅读(305) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 22 下一页