自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

数据艺术家

数据挖掘领域懵逼者

  • 博客(120)
  • 收藏
  • 关注

原创 LeetCode题解(1861):旋转盒子(Python)

题目:原题链接(中等)标签:数组、双指针解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N×M)O(N×M)O(N×M)O(N×M)O(N×M)O(N×M)500ms (41.82%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:

2021-05-24 22:10:26 3

原创 LeetCode题解(1862):向下取整数对和(Python)

题目:原题链接(困难)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)3224ms (72.47%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: _MOD = 10 ** 9 + 7 def sumOfFlooredPairs(self, nums: List[int]) ->

2021-05-24 22:10:22 6

原创 LeetCode题解(1863):找出所有子集的异或总和再求和(Python)

题目:原题链接(简单)标签:回溯算法、递归解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(2N)O(2^N)O(2N)O(N)O(N)O(N)96ms (5)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def __init__(self): self.ans = 0 self.nums = [] def subsetXORS

2021-05-24 22:10:18 34

原创 LeetCode题解(1864):构成交替字符串需要的最小交换次数(Python)

题目:原题链接(中等)标签:贪心算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)32ms (98.79%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def minSwaps(self, s: str) -> int: c0, c1 = s.count("0"), s.count("1")

2021-05-24 22:10:14 9

原创 LeetCode题解(1865):找出和为指定值的下标对(Python)

题目:原题链接(中等)标签:有序映射、设计、哈希表解法时间复杂度空间复杂度执行用时Ans 1 (Python)构造 = O(NlogN)O(NlogN)O(NlogN) ; 操作 = O(logN)O(logN)O(logN)O(N)O(N)O(N)5896ms (5.00%)Ans 2 (Python)Ans 3 (Python)解法一:class FindSumPairs: def __init__(self, nums1: L

2021-05-24 22:10:08 5

原创 LeetCode题解(1866):恰有K根木棍可以看到的排列数目(Python)

题目:原题链接(困难)标签:动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NK2)O(NK^2)O(NK2)O(NK)O(NK)O(NK)超出时间限制Ans 2 (Python)O(NK)O(NK)O(NK)O(NK)O(NK)O(NK)324ms (98.75%)Ans 3 (Python)解法一(记忆化递归):MOD = 10 ** 9 + 7# 计算可能用到的阶乘列表factorials = [1]fa

2021-05-24 22:10:01 4

原创 LeetCode题解(1869):哪种连续子字符串更长(Python)

题目:原题链接(简单)标签:数组、双指针解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)44ms (66.67%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def checkZeroOnes(self, s: str) -> bool: size = len(s) max1, max0

2021-05-24 22:09:57 24

原创 LeetCode题解(1870):准时到达的列车最小时速(Python)

题目:原题链接(中等)标签:二分查找、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogK)O(NlogK)O(NlogK)O(1)O(1)O(1)2260ms (16.67%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def minSpeedOnTime(self, dist: List[int], hour: float) -> int:

2021-05-24 22:09:51 24

原创 LeetCode题解(1871):跳跃游戏VII(Python)

题目:原题链接(中等)标签:贪心算法、广度优先搜索、扫描线算法、堆解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)1932ms (66.67%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def canReach(self, s: str, minJump: int, maxJump: int) -&

2021-05-24 22:09:46 4

原创 LeetCode题解(1872):石子游戏VIII(Python)

题目:原题链接(困难)标签:动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)356ms (33.33%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def stoneGameVIII(self, stones: List[int]) -> int: size = len(stones)

2021-05-24 22:09:42 14

原创 LeetCode题解(1693):每天的领导和合伙人(SQL)

题目:原题链接(简单)标签:SQL解法时间复杂度空间复杂度执行用时Ans 1 (SQL)––364ms (43.84%)Ans 2 (SQL)Ans 3 (SQL)解法一:SELECT date_id, make_name, COUNT(DISTINCT lead_id) AS unique_leads, COUNT(DISTINCT partner_id) AS unique_partnersFR

2021-05-23 22:14:52 2

原创 LeetCode题解(1709):访问日期之间最大的空档期(SQL)

题目:原题链接(中等)标签:SQL解法时间复杂度空间复杂度执行用时Ans 1 (SQL)––382ms (34.66%)Ans 2 (SQL)Ans 3 (SQL)解法一:SELECT user_id, MAX(diff) AS biggest_windowFROM (SELECT user_id, DATEDIFF(LEAD(visit_date, 1, '2021-1-1') OVER (PART

2021-05-23 22:14:45 2

原创 LeetCode题解(1715):苹果和橘子的个数(SQL)

题目:原题链接(中等)标签:SQL解法时间复杂度空间复杂度执行用时Ans 1 (SQL)––661ms (27.58%)Ans 2 (SQL)Ans 3 (SQL)解法一:SELECT SUM(B.apple_count + IFNULL(C.apple_count, 0)) AS apple_count, SUM(B.orange_count + IFNULL(C.orange_count, 0)) AS orange_cou

2021-05-23 22:14:40 3

原创 LeetCode题解(1061):按字典序排列最小的等效字符串(Python)

题目:原题链接(中等)标签:并查集、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(26)O(26)O(26)44ms (97.14%)Ans 2 (Python)Ans 3 (Python)解法一:class DSU: def __init__(self, n: int): self._n = n self._array = [i for i in

2021-05-23 22:14:35 6

原创 LeetCode题解(1101):彼此熟识的最早时间(Python)

题目:原题链接(中等)标签:并查集、排序解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)48ms (100.00%)Ans 2 (Python)Ans 3 (Python)解法一:class DSU: def __init__(self, n: int): self._n = n self._array = [i for i in range(

2021-05-23 22:14:30 4

原创 LeetCode题解(1102):得分最高的路径(Python)

题目:原题链接(中等)标签:广度优先搜索、堆解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)948ms (100.00%)Ans 2 (Python)Ans 3 (Python)解法一:import heapqclass Solution: def maximumMinimumPath(self, grid: List[List[int]]) -&

2021-05-23 22:14:25 5

原创 LeetCode题解(1168):水资源分配优化(Python)

题目:原题链接(困难)标签:图、Prim算法、Kruskal算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)184ms (86.67%)Ans 2 (Python)Ans 3 (Python)解法一:import collectionsimport heapqfrom typing import Listclass Solution: d

2021-05-23 22:14:19 10

原创 LeetCode题解(1135):最低成本联通所有城市(Python)

题目:原题链接(中等)标签:图、Prim算法、Kruskal算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)208ms (62.25%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def minimumCost(self, n: int, connections: List[List[int]])

2021-05-23 22:14:14 10

原创 LeetCode题解(1724):检查边长度限制的路径是否存在II(Python)

题目:原题链接(困难)标签:并查集、图、二进制拆分解法时间复杂度空间复杂度执行用时Ans 1 (Python)构造 = O((N+M)log(N+M))O((N+M)log(N+M))O((N+M)log(N+M)) ; 操作 = O(log(N+M))O(log(N+M))O(log(N+M))O(N+M)O(N+M)O(N+M)1660ms (66.67%)Ans 2 (Python)Ans 3 (Python)解法一:class Dis

2021-05-23 22:14:09 7

原创 LeetCode题解(0644):最大平均子段和II(Python)

题目:原题链接(困难)标签:数组、二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogK)O(NlogK)O(NlogK)O(N)O(N)O(N)1756ms (34.48%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def findMaxAverage(self, nums: List[int], k: int) -> float:

2021-05-23 22:14:05 4

原创 LeetCode题解(0741):摘樱桃(Python)

题目:原题链接(困难)标签:动态规划、记忆化递归解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N3)O(N^3)O(N3)O(N3)O(N^3)O(N3)436ms (85.71%)Ans 2 (Python)Ans 3 (Python)解法一:import functoolsfrom typing import Listclass Solution: def cherryPickup(self, grid:

2021-05-22 21:49:15 9

原创 LeetCode题解(0745):前缀和后缀搜索(Python)

题目:原题链接(困难)标签:字典树解法时间复杂度空间复杂度执行用时Ans 1 (Python)构造 = O(N×S2)O(N×S^2)O(N×S2) ; f = O(S)O(S)O(S)O(S2)O(S^2)O(S2)3208ms (5.32%)Ans 2 (Python)Ans 3 (Python)解法一:class Trie: class _Node: def __init__(self):

2021-05-22 21:49:10 47

原创 LeetCode题解(1092):最短公共超序列(Python)

题目:原题链接(困难)标签:动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N2)O(N^2)O(N2)O(N2)O(N^2)O(N2)492ms (47.06%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def shortestCommonSupersequence(self, str1: str, str2: str) -> str:

2021-05-22 21:49:07 20

原创 LeetCode题解(1125):最小的必要团队(Python)

题目:原题链接(困难)标签:动态规划、记忆化递归、回溯算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(2N×P)O(2^N×P)O(2N×P)O(2N)O(2^N)O(2N)164ms (96.20%)Ans 2 (Python)Ans 3 (Python)解法一:import collectionsimport functoolsfrom copy import copyclass Solution: d

2021-05-22 21:49:02 8

原创 LeetCode题解(1172):餐盘栈(Python)

题目:原题链接(困难)标签:设计、堆、有序映射解法时间复杂度空间复杂度执行用时Ans 1 (Python)每个操作 = O(logN)O(logN)O(logN)O(N)O(N)O(N)124ms (12.00%)Ans 2 (Python)Ans 3 (Python)解法一:import heapqfrom sortedcontainers import SortedListclass DinnerPlates: def __

2021-05-22 21:48:58 4

原创 LeetCode题解(1192):查找集群内的“关键连接”(Python)

题目:原题链接(困难)标签:深度优先搜索、Tarjan算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N+E)O(N+E)O(N+E)O(N+E)O(N+E)O(N+E)916ms (40.22%)Ans 2 (Python)Ans 3 (Python)解法一:import collectionsfrom typing import Listclass Solution: def criticalConne

2021-05-22 21:48:54 6

原创 LeetCode题解(1458):两个子序列的最大点积(Python)

题目:原题链接(困难)标签:动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(M×N)O(M×N)O(M×N)O(M×N)O(M×N)O(M×N)336ms (89.39%)Ans 2 (Python)Ans 3 (Python)解法一:MIN_INT = -10 ** 9class Solution: def maxDotProduct(self, nums1: List[int], nums2: Lis

2021-05-22 21:48:51 4

原创 LeetCode题解(1463):摘樱桃II(Python)

题目:原题链接(困难)标签:动态规划、记忆化递归解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N2×M)O(N^2×M)O(N2×M)O(N2×M)O(N^2×M)O(N2×M)604ms (97.40%)Ans 2 (Python)Ans 3 (Python)解法一:import functoolsclass Solution: def cherryPickup(self, grid: List[List[i

2021-05-22 21:48:47 6

原创 LeetCode题解(1467):两个盒子中球的颜色数相同的概率(Python)

题目:原题链接(困难)标签:数学、回溯算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)––2776ms (17.54%)Ans 2 (Python)Ans 3 (Python)解法一:from itertools import productfrom math import factorialfrom math import prodclass Solution: def getProbability(sel

2021-05-22 21:48:44 9

原创 LeetCode题解(1547):切棍子的最小成本(Python)

题目:原题链接(困难)标签:动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(M3)O(M^3)O(M3)O(M2)O(M^2)O(M2)908ms (57.63%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def minCost(self, n: int, cuts: List[int]) -> int: # 排序cuts并添加左右端点

2021-05-22 21:48:33 6

原创 LeetCode题解(1278):分割回文串III(Python)

题目:原题链接(困难)标签:动态规划、记忆化递归解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N4)O(N^4)O(N4)O(N3)O(N^3)O(N3)4732ms (5.48%)Ans 2 (Python)Ans 3 (Python)解法一(非常暴力的动态规划):MAX_INT = 101class Solution: def palindromePartition(self, s: str, k: int

2021-05-21 21:59:35 4

原创 LeetCode题解(1293):网格中的最短路径(Python)

题目:原题链接(困难)标签:动态规划、广度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(M×N×(M+N))O(M×N×(M+N))O(M×N×(M+N))O(M×N×(M+N))O(M×N×(M+N))O(M×N×(M+N))100ms (77.73%)Ans 2 (Python)Ans 3 (Python)解法一:MAX_INT = 10 ** 10class Solution: def short

2021-05-21 21:59:30 7

原创 LeetCode题解(0664):奇怪的打印机(Python)

题目:原题链接(困难)标签:动态规划、记忆化递归、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N3)O(N^3)O(N3)O(N2)O(N^2)O(N2)476ms (84.45%)Ans 2 (Python)Ans 3 (Python)解法一:import functoolsclass Solution: def strangePrinter(self, s: str) -> int:

2021-05-21 21:59:26 18

原创 LeetCode题解(0675):为高尔夫比赛砍树(Python)

题目:原题链接(困难)标签:广度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(M×N×K)O(M×N×K)O(M×N×K) : 其中K为树木数量O(M×N)O(M×N)O(M×N)9697ms (6.66%)Ans 2 (Python)Ans 3 (Python)解法一(暴力):import collectionsfrom typing import Listclass Solution: def c

2021-05-21 21:59:21 9

原创 LeetCode题解(0689):三个无重叠子数组的最大和(Python)

题目:原题链接(困难)标签:动态规划、数组解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)392ms (21.11%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]:

2021-05-21 21:59:17 13

原创 LeetCode题解(0691):贴纸拼词(Python)

题目:原题链接(困难)标签:动态规划、记忆化递归、回溯算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(2T×N)O(2^T×N)O(2T×N)O(2T)O(2^T)O(2T)540ms (81.67%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def minStickers(self, stickers: List[str], target: str) -&gt

2021-05-21 21:59:10 8

原创 LeetCode题解(0757):设置交集大小至少为2(Python)

题目:原题链接(困难)标签:堆、贪心算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)132ms (28.26%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def intersectionSizeTwo(self, intervals: List[List[int]]) -> int:

2021-05-21 21:59:07 4

原创 LeetCode题解(0773):滑动谜题(Python)

题目:原题链接(困难)标签:广度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(6!)O(6!)O(6!)O(6!)O(6!)O(6!)68ms (35.31%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def slidingPuzzle(self, board: List[List[int]]) -> int: stat = tupl

2021-05-21 21:59:03 6

原创 LeetCode题解(0780):到达终点(Python)

题目:原题链接(困难)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)40ms (59.04%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:

2021-05-21 21:59:00 5

原创 LeetCode题解(0782):变为棋盘(Python)

题目:原题链接(困难)标签:数组、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N2)O(N^2)O(N2)O(N)O(N)O(N)88ms (81.40%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def movesToChessboard(self, board: List[List[int]]) -> int: n = len(bo

2021-05-21 21:58:56 8

空空如也

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人 TA的粉丝

提示
确定要删除当前文章?
取消 删除