- 博客(298)
- 收藏
- 关注
原创 LeetCode题解(面试16.26):计算器(Python)
题目:原题链接(中等)标签:字符串、栈解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)68ms (99.81%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def calculate(self, s: str) -> int: marks = {"+", "-", "*", "/"} s
2020-11-30 21:57:05
28
原创 LeetCode题解(0146):LRU缓存机制(Python)
题目:原题链接(中等)标签:设计、队列解法时间复杂度空间复杂度执行用时Ans 1 (Python)所有操作 = O(1)O(1)O(1)O(N)O(N)O(N)176ms (96.33%)Ans 2 (Python)Ans 3 (Python)解法一:class LRUCache: class Node: __slots__ = ("key", "value", "prev", "next") def
2020-11-30 21:57:00
22
原创 LeetCode题解(面试16.25):LRU缓存(Python)
题目:原题链接(中等)标签:设计、队列解法时间复杂度空间复杂度执行用时Ans 1 (Python)所有操作 = O(1)O(1)O(1)O(N)O(N)O(N)196ms (86.92%)Ans 2 (Python)Ans 3 (Python)解法一(双端队列):class LRUCache: class Node: __slots__ = ("key", "value", "prev", "next")
2020-11-30 21:56:57
26
原创 LeetCode题解(0135):分发糖果(Python)
题目:原题链接(困难)标签:数组、贪心算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)76ms (83.30%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def candy(self, ratings: List[int]) -> int: size = len(ratings)
2020-11-30 21:56:51
28
原创 LeetCode题解(0132):分割回文串II(Python)
题目:原题链接(困难)标签:动态规划、字符串解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N2)O(N^2)O(N2)O(N2)O(N^2)O(N2)404ms (86.90%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def minCut(self, s): size = len(s) # 计算是否为回文串 is
2020-11-30 21:56:46
26
原创 LeetCode题解(0128):最长连续序列(Python)
题目:原题链接(困难)标签:数组、哈希表、并查集解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)48ms (59.62%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: class IntervalArray: class Interval: __slots__ = ("l", "r")
2020-11-30 21:56:42
19
原创 LeetCode题解(0123):买卖股票的最佳时机III(Python)
题目:原题链接(困难)标签:数组、贪心算法、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)384ms (91.51%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def maxProfit(self, prices: List[int]) -> int: # 计算前缀最小值 p
2020-11-30 21:56:35
19
原创 LeetCode题解(0045):跳跃游戏II(Python)
题目:原题链接(困难)标签:数组、贪心算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)40ms (99.70%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def jump(self, nums: List[int]) -> int: size = len(nums) end =
2020-11-30 21:56:30
28
原创 LeetCode题解(0041):缺失的第一个正数(Python)
题目:原题链接(困难)标签:数组解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)44ms (47.72%)Ans 2 (Python)Ans 3 (Python)解法一(每个数最多被遍历三次):class Solution: def firstMissingPositive(self, nums: List[int]) -> int: size = le
2020-11-30 21:56:24
14
原创 LeetCode题解(面试17.25):单词矩阵(Python)
题目:原题链接(困难)标签:哈希表、回溯算法、递归、字典树解法时间复杂度空间复杂度执行用时Ans 1 (Python)––超出时间限制 (28/34)Ans 2 (Python)––2216ms (50.82%)Ans 3 (Python)解法一(暴力递归):class Solution: def maxRectangle(self, words: List[str]) -> List[str]: # 依据单词长
2020-11-30 21:56:18
17
原创 LeetCode题解(面试17.24):最大子矩阵(Python)
题目:原题链接(困难)标签:数组、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N×M2)O(N×M^2)O(N×M2)O(N×M)O(N×M)O(N×M)3288ms (29.62%)Ans 2 (Python)Ans 3 (Python)解法一(动态规划):class Solution: def getMaxMatrix(self, matrix: List[List[int]]) -> List[
2020-11-29 22:58:46
21
原创 LeetCode题解(面试17.19):消失的两个数字(Python)
题目:原题链接(困难)标签:数组、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)60ms (85.67%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def missingTwo(self, nums: List[int]) -> List[int]: size = len(nums) + 2
2020-11-29 22:58:42
16
原创 LeetCode题解(面试17.06):2出现的次数(Python)
题目:原题链接(困难)标签:数学、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)36ms (80.61%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def numberOf2sInRange(self, n: int) -> int: ans = 0 #
2020-11-29 22:58:39
27
原创 LeetCode题解(面试16.22):兰顿蚂蚁(Python)
题目:原题链接(中等)标签:数组解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(K)O(K)O(K)O(K)O(K)O(K)736ms (62.73%)Ans 2 (Python)Ans 3 (Python)解法一(情景模拟):class Solution: def printKMoves(self, K: int) -> List[str]: if K == 0: ret
2020-11-29 22:58:35
30
原创 LeetCode题解(面试16.21):交换和(Python)
LeetCode题解(面试16.21):交换和(Python)题目:原题链接(中等)标签:数组、哈希表、排序解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)52ms (89.57%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def findSwapValues(self, array1: List[int], array
2020-11-29 22:58:30
16
原创 LeetCode题解(面试16.20):T9键盘(Python)
题目:原题链接(中等)标签:数组、哈希表解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(W)O(W)O(W)O(W)O(W)O(W)56ms (71.21%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def getValidT9Words(self, num: str, words: List[str]) -> List[str]: table
2020-11-29 22:58:22
21
原创 LeetCode题解(面试16.19):水域大小(Python)
题目:原题链接(中等)标签:广度优先搜索、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NM)O(N^M)O(NM)O(N×M)O(N×M)O(N×M)364ms (29.88%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def pondSizes(self, land: List[List[int]]) -> List[int]:
2020-11-29 22:58:18
42
原创 LeetCode题解(面试16.18):模式匹配(Python)
题目:原题链接(中等)标签:字符串解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N2)O(N^2)O(N2)O(N)O(N)O(N)416ms (13.98%)Ans 2 (Python)O(N2)O(N^2)O(N2)O(N)O(N)O(N)44ms (65.68%)Ans 3 (Python)解法一(暴力解法):class Solution: def patternMatching(self, pattern:
2020-11-29 22:58:13
21
原创 LeetCode题解(面试16.17):连续数列(Python)
题目:原题链接(简单)标签:数组、分治算法、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)52ms (48.16%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def maxSubArray(self, nums: List[int]) -> int: ans = float("-inf")
2020-11-29 22:58:08
18
原创 LeetCode题解(面试16.16):部分排序(Python)
题目:原题链接(中等)标签:数组、双指针、栈、排序解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)84ms (98.49%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def subSort(self, array: List[int]) -> List[int]: if len(array) <
2020-11-29 22:58:03
18
原创 LeetCode题解(面试16.15):珠玑妙算游戏(Python)
题目:原题链接(简单)标签:数组解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)32ms (94.97%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def masterMind(self, solution: str, guess: str) -> List[int]: ans1, ans2 = 0,
2020-11-28 15:10:25
67
原创 LeetCode题解(面试16.13):平分正方形(Python)
题目:原题链接(中等)标签:几何、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(1)O(1)O(1)O(1)O(1)O(1)32ms (100.00%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def cutSquares(self, square1: List[int], square2: List[int]) -> List[float]:
2020-11-28 15:10:20
32
1
原创 LeetCode题解(面试16.10):生存人数(Python)
题目:原题链接(中等)标签:数组、堆解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)164ms (47.20%)Ans 2 (Python)Ans 3 (Python)解法一(堆):class Solution: def maxAliveYear(self, birth: List[int], death: List[int]) -> int:
2020-11-28 15:10:16
24
原创 LeetCode题解(面试16.09):运算(Python)
题目:原题链接(中等)标签:设计、位运算解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)156ms (22.41%)Ans 2 (Python)Ans 3 (Python)解法一:class Operations: def __init__(self): self.neg_cache = [] self.pos_cache
2020-11-28 15:10:10
31
原创 LeetCode题解(面试16.08):整数的英语表示(Python)
题目:原题链接(困难)标签:分治算法、数学、字符串解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(logN)O(logN)O(logN)44ms (67.12%)Ans 2 (Python)Ans 3 (Python)解法一(分治算法):class Solution: # 处理[0,20)的情况 def count1(self, n): return [
2020-11-28 15:10:06
22
原创 LeetCode题解(面试16.07):最大数值(Python)
题目:原题链接(简单)标签:位运算、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(1)O(1)O(1)O(1)O(1)O(1)36ms (82.96%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def maximum(self, a: int, b: int) -> int: c = a - b d = c >>
2020-11-28 15:10:02
21
原创 LeetCode题解(面试16.06):最小差(Python)
题目:原题链接(中等)标签:二分查找、数组、双指针、排序解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)240ms (63.29%)Ans 2 (Python)Ans 3 (Python)解法一(二分查找):class Solution: def smallestDifference(self, a: List[int], b: List[int])
2020-11-28 15:09:58
30
原创 LeetCode题解(面试16.05):阶乘尾数(Python)
题目:原题链接(简单)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)48ms (20.50%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def trailingZeroes(self, n: int) -> int: ans = 0 now = 5
2020-11-28 15:09:54
17
原创 LeetCode题解(面试16.04):井字游戏(Python)
题目:原题链接(中等)标签:数组解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N2)O(N^2)O(N2)O(1)O(1)O(1)32ms (97.97%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def tictactoe(self, board: List[str]) -> str: size = len(board)
2020-11-28 15:09:48
18
原创 LeetCode题解(面试16.03):交点(Python)
题目:原题链接(困难)标签:几何、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(1)O(1)O(1)O(1)O(1)O(1)44ms (38.46%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def intersection(self, start1: List[int], end1: List[int], start2: List[int], end2: L
2020-11-28 15:09:43
22
原创 LeetCode题解(面试16.01):交换数字(Python)
题目:原题链接(中等)标签:位运算、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(1)O(1)O(1)O(1)O(1)O(1)36ms (81.27%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def swapNumbers(self, numbers: List[int]) -> List[int]: numbers[0] = numb
2020-11-27 06:58:40
20
原创 LeetCode题解(面试10.11):峰与谷(Python)
题目:原题链接(中等)标签:数组、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)48ms (73.43%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def wiggleSort(self, nums: List[int]) -> None: size = len(nums) pe
2020-11-27 06:58:36
23
原创 LeetCode题解(面试10.10):数字流的秩(Python)
题目:原题链接(中等)标签:树状数组、线段树解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(50000)O(50000)O(50000)100ms (71.83%)Ans 2 (Python)Ans 3 (Python)解法一:class BIT: def __init__(self, n: int): self.n = n self._t
2020-11-27 06:58:32
39
原创 LeetCode题解(面试10.09):排序矩阵查找(Python)
题目:原题链接(中等)标签:二分查找、双指针、分治算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)52ms (46.34%)Ans 2 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)44ms (83.92%)Ans 3 (Python)解法一:class Solution: def searchMatrix(self, matrix:
2020-11-27 06:58:27
41
原创 LeetCode题解(面试10.05):稀疏数组搜索(Python)
题目:原题链接(简单)标签:二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)40ms (69.64%)Ans 2 (Python)Ans 3 (Python)解法一(二分查找):class Solution: def findString(self, words: List[str], s: str) -> int: left, right =
2020-11-27 06:58:22
17
原创 LeetCode题解(0164):最大间距(Python)
题目:原题链接(困难)标签:排序、基数排序解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(KN)O(KN)O(KN)O(N)O(N)O(N)52ms (58.01%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def maximumGap(self, nums: List[int]) -> int: if len(nums) < 2:
2020-11-27 06:58:17
42
原创 LeetCode题解(0262):行程和用户(SQL)
题目:原题链接(困难)标签:SQL解法时间复杂度空间复杂度执行用时Ans 1 (Python)287ms (68.84%)Ans 2 (Python)Ans 3 (Python)解法一:SELECT T.Request_at AS `Day`, ROUND(SUM(IF(T.Status = 'completed', 0, 1)) / COUNT(T.Status), 2) AS `Cancellation Rate`FROM
2020-11-27 06:58:12
16
原创 LeetCode题解(0185):部门工资前三高的所有员工(SQL)
题目:原题链接(困难)标签:SQL解法时间复杂度空间复杂度执行用时Ans 1 (Python)957ms (34.12%)Ans 2 (Python)Ans 3 (Python)Create table If Not Exists Employee( Id int, Name varchar(255), Salary int, DepartmentId int);Create table If Not Ex
2020-11-27 06:58:07
25
原创 LeetCode题解(0184):部门工资最高的员工(SQL)
题目:原题链接(中等)标签:SQL解法时间复杂度空间复杂度执行用时Ans 1 (Python)496ms (54.55%)Ans 2 (Python)Ans 3 (Python)解法一:SELECT Department.name AS Department, Employee.name AS Employee, salary AS SalaryFROM Employee JOIN D
2020-11-27 06:58:03
15
原创 LeetCode题解(0180):连续出现的数字(SQL)
题目:原题链接(中等)标签:SQL解法时间复杂度空间复杂度执行用时Ans 1 (Python)372ms (59.20%)Ans 2 (Python)Ans 3 (Python)解法一:SELECT DISTINCT log1.num AS 'ConsecutiveNums'FROM logs AS log1, logs AS log2, logs AS log3WHERE log1.id = log2.id - 1
2020-11-27 06:57:56
19
空空如也
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人 TA的粉丝