自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

数据艺术家

数据挖掘领域懵逼者

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

原创 LeetCode题解(Offer57I):寻找数组中两个和为目标值的数(Python)

题目:原题链接(简单)标签:数组、集合解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)168ms (51.34%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: lst = set()

2020-10-31 09:43:59 18

原创 LeetCode题解(Offer56II):数组中数字出现的次数 II(Python)

题目:原题链接(中等)标签:位运算、数组、集合解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)64ms (79.14%)Ans 2 (Python)O(N)O(N)O(N)O(1)O(1)O(1)96ms (45.91%)Ans 3 (Python)解法一(集合):class Solution: def singleNumber(self, nums: List[int])

2020-10-31 09:43:16 13

原创 LeetCode题解(Offer56I):寻找数组中仅出现一次的数字(Python)

题目:原题链接(中等)标签:位运算、数组解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)60ms (68.74%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def singleNumbers(self, nums: List[int]) -> List[int]: # 找到只出现了一次的两个数的异或结

2020-10-31 09:43:10 16

原创 LeetCode题解(Offer55II):判断二叉树是否为高度平衡的二叉树(Python)

题目:原题链接(简单)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)60ms (83.75%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def __init__(self): self.ans = True def isBalanced(self, root: Tr

2020-10-31 09:43:04 9

原创 LeetCode题解(Offer55I):计算二叉树的最大深度(Python)

题目:原题链接(简单)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)48ms (89.29%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def maxDepth(self, root: TreeNode) -> int: if not root:

2020-10-31 09:43:00 10

原创 LeetCode题解(Offer54):寻找二叉搜索树中的第k大节点(Python)

题目:原题链接(简单)标签:树、二叉树、二叉搜索树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(K+H)O(K+H)O(K+H)O(H)O(H)O(H)72ms (40.32%)Ans 2 (Python)Ans 3 (Python)解法一(反向中序遍历):class Solution: def __init__(self): self.idx = 0 self.ans

2020-10-31 09:42:54 11

原创 LeetCode题解(Offer53II):找出排序数组中缺失的整数(Python)

题目:原题链接(简单)标签:数组、二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)44ms (78.76%)Ans 2 (Python)Ans 3 (Python)解法一(二分查找):class Solution: def missingNumber(self, nums: List[int]) -> int: left, ri

2020-10-31 09:42:48 19

原创 LeetCode题解(0034):在排序数组中查找元素的第一个和最后一个位置(Python)

题目:原题链接(中等)标签:数组、二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)44ms (57.43%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def searchRange(self, nums: List[int], target: int) -> List[int]:

2020-10-31 09:42:42 28

原创 LeetCode题解(Offer53I):计算排序数组中指定数字的数量(Python)

题目:原题链接(简单)标签:数组、二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)44ms (60.00%)Ans 2 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)44ms (60.00%)Ans 3 (Python)解法一:class Solution: def search(self, nums: List[int], tar

2020-10-31 09:42:38 11

原创 LeetCode题解(Offer52):寻找两个链表的第一个公共节点(Python)

题目:原题链接(简单)标签:链表、链表-相交链表、链表-双指针、链表-快慢针解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N1+N2)O(N1+N2)O(N1+N2)O(1)O(1)O(1)184ms (77.73%)Ans 2 (Python)Ans 3 (Python)解法一(双指针):class Solution: def getIntersectionNode(self, headA: ListNode, h

2020-10-31 09:42:33 10

原创 LeetCode题解(Offer51):计算数组中逆序对的数量(Python)

题目:原题链接(困难)标签:数组、数学、二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)2464ms (6.88%)Ans 2 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)1452ms (91.75%)Ans 3 (Python)解法一(二分查找):class Solution: def revers

2020-10-30 23:13:19 27

原创 LeetCode题解(Offer50):寻找字符串中第一个只出现一次的字符(Python)

题目:原题链接(中等)标签:哈希表解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)76ms (96.79%)Ans 2 (Python)Ans 3 (Python)解法一(哈希表):class Solution: def firstUniqChar(self, s: str) -> str: order = [] more = set()

2020-10-30 23:13:14 34

原创 LeetCode题解(0264):计算第N个丑数(Python)

题目:原题链接(中等)标签:数学、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)156ms (81.43%)Ans 2 (Python)Ans 3 (Python)解法一(动态规划):class Solution: def nthUglyNumber(self, n: int) -> int: dp = [1] * n i1,

2020-10-30 23:13:10 19

原创 LeetCode题解(Offer49):计算第N个丑数(Python)

题目:原题链接(中等)标签:数学、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(MlogM)O(MlogM)O(MlogM) : M为丑数的个数O(1)O(1)O(1)超出时间限制Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)148ms (94.04%)Ans 3 (Python)解法一(最暴力的暴力解法):class Solution: def nthUglyNumber(se

2020-10-30 23:13:03 13

原创 LeetCode题解(Offer48):寻找字符串中最长不含重复字符的子字符串(Python)

题目:原题链接(中等)标签:哈希表、双指针、移动窗口解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)104ms (22.40%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)60ms (97.85%)Ans 3 (Python)解法一:class Solution: def lengthOfLongestSubstring(self, s: st

2020-10-30 23:12:59 21

原创 LeetCode题解(Offer47):计算从礼物二维数组的左上角向右下走到右下角所能得到的礼物最大值(Python)

题目:原题链接(中等)标签:数组、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N×M)O(N×M)O(N×M)O(N×M)O(N×M)O(N×M)52ms (92.89%)Ans 2 (Python)Ans 3 (Python)解法一(动态规划):class Solution: def maxValue(self, grid: List[List[int]]) -> int: if n

2020-10-30 23:12:55 30

原创 LeetCode题解(Offer46):把数字翻译成字符串(Python)

题目:原题链接(中等)标签:数组、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)32ms (95.96%)Ans 2 (Python)O(N)O(N)O(N)O(1)O(1)O(1)36ms (86.92%)Ans 3 (Python)解法一(动态规划):class Solution: def translateNum(self, num: int) -> i

2020-10-30 23:12:51 26

原创 LeetCode题解(Offer44):计算0123456789101112...格式化序列中某一位的数字(Python)

题目:原题链接(中等)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)32ms (96.49%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def findNthDigit(self, n: int) -> int: # 处理特殊情况 if n == 0:

2020-10-30 23:12:47 22

原创 LeetCode题解(0233):计算n个整数中数字1出现的次数(Python)

题目:原题链接(困难)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)44ms (37.13%)Ans 2 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)36ms (87.74%)Ans 3 (Python)解法一:class Solution: def countDigitOne(self, n: int) -

2020-10-30 23:12:43 14

原创 LeetCode题解(Offer41):数据流中的中位数(Python)

题目:原题链接(困难)标签:二分查找、设计解法时间复杂度空间复杂度执行用时Ans 1 (Python)addNum = O(logN)O(logN)O(logN) ; findMedian = O(1)O(1)O(1)O(N)O(N)O(N)282ms (50.00%)Ans 2 (Python)Ans 3 (Python)解法一(二分查找):class MedianFinder: def __init__(self):

2020-10-30 23:12:39 17

原创 LeetCode题解(Offer45):把非负整数数组排成一个最小的数(Python)

题目:原题链接(中等)标签:数学、排序解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(NlogN)O(NlogN)O(NlogN)O(N)O(N)O(N)40ms (95.95%)Ans 2 (Python)Ans 3 (Python)解法一(自定义排序):class Solution: def minNumber(self, nums: List[int]) -> str: nums = [st

2020-10-29 23:41:33 20

原创 LeetCode题解(0400):计算0123456789101112...格式化序列中某一位的数字(Python)

题目:原题链接(中等)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)36ms (86.21%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def findNthDigit(self, n: int) -> int: # 处理特殊情况 if n == 0:

2020-10-29 23:41:28 9

原创 LeetCode题解(Offer43):计算n个整数中数字1出现的次数(Python)

题目:原题链接(中等)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N) : 其中N为数值的位数O(N)O(N)O(N)32ms (96.57%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def countDigitOne(self, n: int) -> int: ans = 0 s = str(

2020-10-29 23:41:24 27

原创 LeetCode题解(Offer42):找出整数数组中一个具有最大和的连续子数组(Python)

题目:原题链接(简单)标签:数组、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)144ms (5.67%)Ans 2 (Python)O(N)O(N)O(N)O(1)O(1)O(1)60ms (96.62%)Ans 3 (Python)解法一:class Solution: def maxSubArray(self, nums: List[int]) -> i

2020-10-29 23:41:20 80

原创 LeetCode题解(0295):数据流的中位数(Python)

题目:原题链接(困难)标签:二分查找、设计解法时间复杂度空间复杂度执行用时Ans 1 (Python)addNum = O(logN)O(logN)O(logN) ; findMedian = O(1)O(1)O(1)O(N)O(N)O(N)276ms (41.51%)Ans 2 (Python)Ans 3 (Python)解法一(二分查找):import bisectclass MedianFinder: def __ini

2020-10-29 23:41:16 8

原创 LeetCode题解(Offer40):寻找数组中最小的k个数(Python)

题目:原题链接(简单)标签:堆解法时间复杂度空间复杂度执行用时Ans 1 (Python)–O(N)O(N)O(N)76ms (59.37%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def getLeastNumbers(self, arr: List[int], k: int) -> List[int]: heapq.heapify(arr)

2020-10-29 23:41:12 20

原创 LeetCode题解(Offer39):数组中出现次数超过一半的数字(Python)

题目:原题链接(简单)标签:数组、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)52ms (70.50%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def majorityElement(self, nums: List[int]) -> int: last = None num

2020-10-29 23:41:07 14

原创 LeetCode题解(Offer38):生成字符串中字母的全排列(Python)

题目:原题链接(中等)标签:字符串、回溯算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N!)O(N!)O(N!)O(N!)O(N!)O(N!)464ms (9.31%)Ans 2 (Python)O(N!)O(N!)O(N!)O(N!)O(N!)O(N!)112ms (95.61%)Ans 3 (Python)O(N!)O(N!)O(N!)O(N!)O(N!)O(N!)84ms (98.78%)解法一(递归):class

2020-10-29 23:41:04 22

原创 LeetCode题解(Offer37):“将二叉树序列化为文本”与“从文本反序列化为二叉树”(Python)

题目:原题链接(困难)标签:树、二叉树、广度优先搜索、设计解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)156ms (52.62%)Ans 2 (Python)Ans 3 (Python)解法一:class Codec: def serialize(self, root): """Encodes a tree to a single string.

2020-10-29 23:40:59 11

原创 LeetCode题解(Offer31):判断两个序列是否可能为栈的压入和弹出序列(Python)

题目:原题链接(中等)标签:栈、情景模拟解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)48ms (60.94%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)52ms (35.79%)Ans 3 (Python)解法一(情景模拟1):class Solution: def validateStackSequences(self, pushed:

2020-10-29 23:40:55 12

原创 LeetCode题解(Offer36):将二叉搜索树就地转换为双向链表(Python)

题目:原题链接(中等)标签:树、二叉树、二叉搜索树、链表、分治算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)44ms (83.61%)Ans 2 (Python)Ans 3 (Python)解法一(中序遍历二叉树):class Solution: def __init__(self): self.last = None self.firs

2020-10-18 22:38:49 17

原创 LeetCode题解(Offer35):复制带随机指针的链表(Python)

题目:原题链接(中等)标签:链表、链表-特殊链表、哈希表解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)52ms (45.41%)Ans 2 (Python)Ans 3 (Python)解法一(哈希表):class Solution: def copyRandomList(self, head: 'Node') -> 'Node': ans = node

2020-10-18 22:38:45 16

原创 LeetCode题解(Offer34):寻找二叉树中所有根节点到叶节点的路径和为目标值的路径(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(H)O(H)O(H)48ms (89.19%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def __init__(self): self.lst = [] self.val = 0 self.an

2020-10-18 22:38:41 25

原创 LeetCode题解(Offer33):判断整数数组是否可能为某二叉搜索树的后序遍历结果(Python)

题目:原题链接(中等)标签:树、二叉树、数学、递归解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)44ms (57.89%)Ans 2 (Python)Ans 3 (Python)解法一(递归):class Solution: def verifyPostorder(self, postorder: List[int]) -> bool: if not

2020-10-18 22:38:37 19

原创 LeetCode题解(Offer32III):锯齿形层次遍历二叉树(Python)

题目:原题链接(中等)标签:树、二叉树、广度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)44ms (64.14%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def levelOrder(self, root: TreeNode) -> List[List[int]]: if not roo

2020-10-18 22:38:31 16

原创 LeetCode题解(Offer32II):实现二叉树的层序遍历(分层输出)(Python)

题目:原题链接(中等)标签:树、二叉树、广度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)44ms (63.15%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def levelOrder(self, root: TreeNode) -> List[List[int]]: if not roo

2020-10-18 22:38:27 17

原创 LeetCode题解(Offer32I):实现二叉树的层序遍历(不分层输出)(Python)

题目:原题链接(中等)标签:树、二叉树、广度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)44ms (61.95%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def levelOrder(self, root: TreeNode) -> List[int]: if not root:

2020-10-18 22:38:22 19

原创 LeetCode题解(Offer30):设计能够在常数时间内检索到最小元素的栈(Python)

题目:原题链接(简单)标签:栈、设计解法时间复杂度空间复杂度执行用时Ans 1 (Python)push = O(1)O(1)O(1) ; pop = O(N)O(N)O(N) ; top = O(1)O(1)O(1) ; getMin = O(1)O(1)O(1)O(N)O(N)O(N)72ms (92.58%)Ans 2 (Python)Ans 3 (Python)解法一:class MinStack: def __init__(

2020-10-18 22:38:18 24

原创 LeetCode题解(0054):螺旋矩阵(Python)

题目:原题链接(中等)标签:数组解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(X×Y)O(X×Y)O(X×Y)O(1)O(1)O(1)36ms (85.56%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: # 处理空表的情况

2020-10-18 22:38:14 18

原创 LeetCode题解(Offer29):顺时针从外向内打印矩阵(Python)

题目:原题链接(简单)标签:数组解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(X×Y)O(X×Y)O(X×Y)O(1)O(1)O(1)48ms (74.02%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: # 处理空表的情况

2020-10-18 22:38:10 25

空空如也

空空如也

空空如也

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

TA关注的人 TA的粉丝

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