随笔分类 -  leetcode

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 22 下一页
摘要:题目描述: 自己的提交: class Solution: def balancedStringSplit(self, s: str) -> int: if not s:return 0 res = 0 c = {} tmp = None for r in s: if not c: tmp = r c 阅读全文
posted @ 2019-10-14 08:43 oldby 阅读(216) 评论(0) 推荐(0)
摘要:题目描述: 方法:剥洋葱 class Solution: def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]: if n==1:return [0] e = collections.defaultdict 阅读全文
posted @ 2019-10-12 11:42 oldby 阅读(80) 评论(0) 推荐(0)
摘要:方法一:dfs+图 class Solution: def calcEquation(self, equations: List[List[str]], values: List[float], queries: List[List[str]]) -> List[float]: graph = {} 阅读全文
posted @ 2019-10-11 20:31 oldby 阅读(243) 评论(0) 推荐(0)
摘要:- 题目:130 并查集: class Solution: def solve(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place instead. """ f = {} d 阅读全文
posted @ 2019-10-11 20:31 oldby 阅读(525) 评论(0) 推荐(0)
摘要:题目描述: 方法一:集合 O(N) class Solution: def longestConsecutive(self, nums: List[int]) -> int: nums = set(nums) res = 0 for num in nums: if num-1 not in nums 阅读全文
posted @ 2019-10-11 15:21 oldby 阅读(177) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 O(Nk) class Solution: def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int: dp = [1] * n l = [0]*len(primes) for i in range(1 阅读全文
posted @ 2019-10-11 10:33 oldby 阅读(161) 评论(0) 推荐(0)
摘要:题目描述: 方法一:递归 class Solution: def isUgly(self, num: int) -> bool: if num == 0: return False if num == 1:return True if num % 2 == 0: return self.isUgly 阅读全文
posted @ 2019-10-11 10:01 oldby 阅读(232) 评论(0) 推荐(0)
摘要:题目描述: 方法一:堆 O(nlogn) class Solution: def nthUglyNumber(self, n: int) -> int: import heapq heap = [1] res = 0 heapq.heapify(heap) for _ in range(n): re 阅读全文
posted @ 2019-10-11 09:39 oldby 阅读(172) 评论(0) 推荐(0)
摘要:题目描述: 方法一:暴力 O(nk) class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: n = len(nums) if n*k == 0: return [] return [max( 阅读全文
posted @ 2019-10-10 20:24 oldby 阅读(212) 评论(0) 推荐(0)
摘要:题目描述: 方法一:分治 O(nlogn) class Solution: def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]: if not buildings:return [] if len(buildings 阅读全文
posted @ 2019-10-10 13:37 oldby 阅读(554) 评论(0) 推荐(0)
摘要:题目169: 分治:O(nlgn) class Solution: def majorityElement(self, nums: List[int]) -> int: def majorE(lo,hi): if lo == hi: return nums[lo] mid = (lo + hi)// 阅读全文
posted @ 2019-10-10 10:41 oldby 阅读(349) 评论(0) 推荐(0)
摘要:题目描述: 方法一:分治 O(kn*logk) O(logk) # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None clas 阅读全文
posted @ 2019-10-10 10:23 oldby 阅读(148) 评论(0) 推荐(0)
摘要:题目描述: 方法:二分 O(log(min(m,n))) class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: n1 = len(nums1) n2 = len(n 阅读全文
posted @ 2019-10-09 20:02 oldby 阅读(162) 评论(0) 推荐(0)
摘要:题目描述: 可参考:题215 方法一:排序 class Solution: def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]: points.sort(key = lambda P: P[0]**2 + P[ 阅读全文
posted @ 2019-10-09 12:49 oldby 阅读(267) 评论(0) 推荐(0)
摘要:题目描述: 方法一:排序 O(nlogn) class Solution: def isAnagram(self, s: str, t: str) -> bool: return sorted(s)==sorted(t) 方法二:哈希表 O(N) O(1) class Solution: def i 阅读全文
posted @ 2019-10-08 10:25 oldby 阅读(105) 评论(0) 推荐(0)
摘要:题目描述: 方法:分治* class Solution: def diffWaysToCompute(self, input: str) -> List[int]: if input.isdigit(): return [int(input)] tem = [] for k in range(len 阅读全文
posted @ 2019-10-08 10:08 oldby 阅读(212) 评论(0) 推荐(0)
摘要:题目描述: 最佳方法:O(m+n) O(1) class Solution: def searchMatrix(self, matrix, target): if not matrix : return False row = len(matrix) col = len(matrix[0]) i = 阅读全文
posted @ 2019-10-07 21:04 oldby 阅读(186) 评论(0) 推荐(0)
摘要:方法: class Solution: def productExceptSelf(self, nums: [int]) -> [int]: res, p, q = [1], 1, 1 for i in range(len(nums) - 1): # top triangle p *= nums[i 阅读全文
posted @ 2019-10-07 19:33 oldby 阅读(116) 评论(0) 推荐(0)
摘要:题目描述: 方法: class Solution: def deleteNode(self, node): """ :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. """ 阅读全文
posted @ 2019-10-07 19:08 oldby 阅读(160) 评论(0) 推荐(0)
摘要:题目描述: 方法一: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class 阅读全文
posted @ 2019-10-07 17:28 oldby 阅读(169) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 22 下一页