摘要:
题目描述: 方法一:堆 O(nlogn) class Solution: def nthUglyNumber(self, n: int) -> int: import heapq heap = [1] res = 0 heapq.heapify(heap) for _ in range(n): re 阅读全文
摘要:
题目描述: 方法一:暴力 O(nk) class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: n = len(nums) if n*k == 0: return [] return [max( 阅读全文
摘要:
题目描述: 方法一:分治 O(nlogn) class Solution: def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]: if not buildings:return [] if len(buildings 阅读全文
摘要:
题目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)// 阅读全文
摘要:
题目描述: 方法一:分治 O(kn*logk) O(logk) # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None clas 阅读全文
摘要:
题目描述: 方法:二分 O(log(min(m,n))) class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: n1 = len(nums1) n2 = len(n 阅读全文
摘要:
题目描述: 可参考:题215 方法一:排序 class Solution: def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]: points.sort(key = lambda P: P[0]**2 + P[ 阅读全文
摘要:
题目描述: 方法一:排序 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 阅读全文
摘要:
题目描述: 方法:分治* class Solution: def diffWaysToCompute(self, input: str) -> List[int]: if input.isdigit(): return [int(input)] tem = [] for k in range(len 阅读全文
摘要:
题目描述: 最佳方法: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 = 阅读全文