自定义博客皮肤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 238

原创 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 251

原创 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 253

原创 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 197

原创 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 212

原创 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 247

原创 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 273

原创 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 231

原创 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 218

原创 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 229

原创 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 428

原创 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 374

原创 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 229

原创 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 221

原创 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 203

原创 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 583

原创 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 252

原创 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 421

原创 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 251

原创 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 223

原创 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 403

原创 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 234

原创 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 289

原创 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 685

原创 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 150

原创 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 363

原创 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 227

原创 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 328

原创 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 180

原创 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 411

原创 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 212

原创 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 190

原创 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 334

原创 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 302

原创 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 185

原创 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 211

原创 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 192

原创 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 244

原创 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 208

原创 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 275

Kaggle:tmdb-box-office-prediction(转结构化数据,用于 SQL 练习)

原数据源(将其训练集结构化): https://www.kaggle.com/c/tmdb-box-office-prediction/data 数据量级+建表语句(含字段含义注释)详见博客: https://dataartist.blog.csdn.net/article/details/132268426 共 15 个表: - movies:电影表 - belongs_to_collection:电影系列表 - person:人员表(演员与剧组人员) - cast_rela:电影与演员的关联表 - crew_rela:电影与剧组人员的关联表 - genres:电影体裁表 - genres_rela:电影与体裁关联表 - keywords:电影关键词表 - keywords_rela:电影与关键词关联表 - production_companies:电影制作公司表 - production_companies_rela:电影与制作公司关联表 - production_countries:电影制作国家表 ……

2023-08-14

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

TA关注的人

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