上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 47 下一页
摘要: 题目描述: 方法一:堆 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 阅读(164) 评论(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 阅读(202) 评论(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 阅读(534) 评论(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 阅读(320) 评论(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 阅读(145) 评论(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 阅读(152) 评论(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 阅读(253) 评论(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 阅读(94) 评论(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 阅读(204) 评论(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 阅读(175) 评论(0) 推荐(0) 编辑
上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 47 下一页