自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

数据艺术家

数据挖掘领域懵逼者

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

原创 LeetCode题解(0050):Pow(x,n)(Python)

题目:原题链接(中等)标签:数学、递归、二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)36ms (90.91%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def myPow(self, x: float, n: int) -> float: if n < 0:

2020-09-19 22:13:17 45

原创 LeetCode题解(Offer16):数值的整数次方计算(Python)

题目:原题链接(中等)标签:数学、递归解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)超出时间限制Ans 2 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)36ms (91.19%)Ans 3 (Python)解法一(暴力算法):class Solution: def myPow(self, x: float, n: int) ->

2020-09-19 22:13:13 48

原创 LeetCode题解(Offer15):计算二进制数中1的数量(Python)

题目:原题链接(简单)标签:位运算解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N) : 其中N为二进制位数O(1)O(1)O(1)44ms (53.95%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def hammingWeight(self, n: int) -> int: ans = 0 while n:

2020-09-19 22:13:09 46

原创 LeetCode题解(0343):将整数n拆分为m个和为n的整数,求m个整数的最大乘积(Python)

题目:原题链接(中等)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)最坏情况时间复杂度 : O(N2)O(N^2)O(N2)O(N)O(N)O(N)40ms (80.65%)Ans 2 (Python)O(N)O(N)O(N)O(1)O(1)O(1)44ms (61.63%)Ans 3 (Python)解法一(数学):class Solution: def integerBreak(self, n: int)

2020-09-19 22:13:00 108

原创 LeetCode题解(Offer14II):将整数n拆分为m个和为n的整数,求m个整数的最大乘积(结果取模)(Python)

题目:原题链接(中等)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)最坏情况时间复杂度 : O(N2)O(N^2)O(N2)O(N)O(N)O(N)92ms (38.63%)Ans 2 (Python)O(N)O(N)O(N)O(1)O(1)O(1)36ms (93.45%)Ans 3 (Python)解法一(数学):class Solution: def cuttingRope(self, n: int) -

2020-09-19 22:12:55 64

原创 LeetCode题解(Offer14I):将整数n拆分为m个和为n的整数,求m个整数的最大乘积(Python)

题目:原题链接(中等)标签:数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)最坏平均复杂度 : O(N2)O(N^2)O(N2)O(N)O(N)O(N)36ms (92.78%)Ans 2 (Python)Ans 3 (Python)解法一(数学):class Solution: def cuttingRope(self, n: int) -> int: ans = 0 for m

2020-09-19 22:12:51 37

原创 LeetCode题解(Offer13):符合指定要求的格坐标数量(Python)

题目:原题链接(中等)标签:分治算法、广度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N×M)O(N×M)O(N×M)O(1)O(1)O(1)52ms (89.27%)Ans 2 (Python)O(N10×M10)=O(N×M)O(\frac{N}{10}×\frac{M}{10}) = O(N×M)O(10N​×10M​)=O(N×M)O(1)O(1)O(1)36ms (99.90%)Ans 3 (Python)

2020-09-19 22:12:47 33

原创 LeetCode题解(Offer12):在二维数组中寻找单词是否由连续的字母元素组成(Python)

题目:原题链接(中等)标签:回溯算法、数组、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N1×N2)O(N1×N2)O(N1×N2)O(N1×N2)O(N1×N2)O(N1×N2)60ms (99.98%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def exist(self, board: List[List[str]], word: str)

2020-09-19 22:12:43 33

原创 LeetCode题解(Offer10I):计算斐波那契数列(Python)

题目:原题链接(简单)标签:递归、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)40ms (69.68%)Ans 2 (Python)Ans 3 (Python)解法一(迭代):class Solution: def fib(self, n: int) -> int: if n == 0: return 0

2020-09-19 22:12:36 26

原创 LeetCode题解(Offer05):将字符串中的空格替换为“%20“(Python)

题目:原题链接(简单)标签:字符串解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)40ms (65.76%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def replaceSpace(self, s: str) -> str: return s.replace(" ","%20")...

2020-09-19 21:41:26 37

原创 LeetCode题解(0153):寻找旋转递增排序数组的最小数字(不存在重复值)(Python)

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

2020-09-18 22:59:09 42

原创 LeetCode题解(0154):寻找旋转递增排序数组的最小数字(存在重复值)(Python)

题目:原题链接(困难)标签:数组、二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)平均时间复杂度 = O(logN)O(logN)O(logN) ; 最坏时间复杂度 = O(N)O(N)O(N)O(1)O(1)O(1)36ms (92.56%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def findMin(self, nums: List[int]) -&gt

2020-09-18 22:59:05 38

原创 LeetCode题解(Offer10II):青蛙跳台阶问题(Python)

题目:原题链接(简单)标签:递归、数学、动态规划解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(1)O(1)O(1)24ms (99.87%)Ans 2 (Python)Ans 3 (Python)解法一(动态规划):[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xZCHIGdo-1600211974096)(LeetCode题解(Offer10II)]:截图.png)

2020-09-18 22:59:02 42

原创 LeetCode题解(Offer11):旋转数组的最小数字(Python)

题目:原题链接(简单)标签:数组、二分查找解法时间复杂度空间复杂度执行用时Ans 1 (Python)平均时间复杂度 = O(logN)O(logN)O(logN) ; 最坏时间复杂度 = O(N)O(N)O(N)O(1)O(1)O(1)44ms (55.71%)Ans 2 (Python)Ans 3 (Python)解法一(二分查找):class Solution: def minArray(self, numbers: List[

2020-09-18 22:58:58 29

原创 LeetCode题解(Offer09):用两个栈实现队列(Python)

题目:原题链接(简单)标签:栈、设计、队列解法时间复杂度空间复杂度执行用时Ans 1 (Python)appendTail = O(1)O(1)O(1) ; deleteHead = O(N)O(N)O(N)O(N)O(N)O(N)超出时间限制Ans 2 (Python)appendTail = O(1)O(1)O(1) ; deleteHead = O(1)O(1)O(1)O(N)O(N)O(N)1528ms (14.36%)Ans 3 (Python)

2020-09-18 22:58:52 25

原创 LeetCode题解(Offer06):从尾到头打印链表(Python)

题目:原题链接(简单)标签:链表解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)52ms (55.06%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def reversePrint(self, head: ListNode) -> List[int]: lst = [] while h

2020-09-18 22:58:48 24

原创 LeetCode题解(Offer07):从前序与中序遍历序列构造二叉树(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)204ms (40.78%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)100ms (71.18%)Ans 3 (Python)解法一(递归):class Solution: def buildTree(self, preorder: List[

2020-09-18 22:58:44 40

原创 LeetCode题解(0240):搜索顺序二维数组(Python)

题目:原题链接(简单)标签:数组、二分查找、双指针解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N×logM)O(N×logM)O(N×logM)O(1)O(1)O(1)44ms (87.05%)Ans 2 (Python)O(N+M)O(N+M)O(N+M)O(1)O(1)O(1)40ms (95.46%)Ans 3 (Python)O(N+M)O(N+M)O(N+M)O(1)O(1)O(1)48ms (70.69%)解法一

2020-09-18 22:58:41 30 1

原创 LeetCode题解(1530):计算二叉树中距离在指定范围内的叶节点对数量(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)216ms (66.79%)Ans 2 (Python)Ans 3 (Python)解法一(深度优先搜索):class Solution: def __init__(self): self.ans = 0 def countPairs(self, ro

2020-09-18 22:58:37 30

原创 LeetCode题解(1448):统计二叉树中好节点的数目(没有比自己的值大的父节点的节点为好节点)(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)332ms (43.65%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)288ms (81.76%)Ans 3 (Python)解法一:class Solution: def goodNodes(self, root: TreeNode, las

2020-09-18 22:58:33 21

原创 LeetCode题解(Offer04):在顺序二维数组中查找(Python)

题目:原题链接(简单)标签:数组、二分查找、双指针解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N×logM)O(N×logM)O(N×logM)O(1)O(1)O(1)52ms (48.16%)Ans 2 (Python)O(N+M)O(N+M)O(N+M)O(1)O(1)O(1)52ms (48.16%)Ans 3 (Python)O(N+M)O(N+M)O(N+M)O(1)O(1)O(1)40ms (94.46%)解法一

2020-09-17 05:28:48 36

原创 LeetCode题解(Offer03):寻找数组中重复的数字(Python)

题目:原题链接(简单)标签:数组、集合解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(K)O(K)O(K) : 其中K为第一个重复元素的坐标O(K)O(K)O(K)52ms (81.12%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def findRepeatNumber(self, nums: List[int]) -> int: hashm

2020-09-17 05:28:41 30

原创 LeetCode题解(1466):调整有向图中边的方向使所有节点都能到达指定点的最少调整方向数(Python)

题目:原题链接(中等)标签:树、深度优先搜索、图、图-无向图解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N+E)O(N+E)O(N+E) : 其中E为连接数O(N+E)O(N+E)O(N+E)468ms (22.94%)Ans 2 (Python)O(N×H)O(N×H)O(N×H) : 其中H为最大深度O(1)O(1)O(1)104ms (99.08%)Ans 3 (Python)解法一:def build_graph_

2020-09-17 05:28:37 43

原创 LeetCode题解(1457):计算二叉树中的伪回文路径数量(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索、位运算解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)492ms (70.81%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def __init__(self): self.ans = 0 def pseudoPalindromicPaths(

2020-09-17 05:28:32 29

原创 LeetCode题解(1443):收集无向树中所有苹果的最少移动距离(Python)

题目:原题链接(中等)标签:树、深度优先搜索、图、图-无向图解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N+E)O(N+E)O(N+E) : 其中E为边数O(N+E)O(N+E)O(N+E)320ms (22.69%)Ans 2 (Python)Ans 3 (Python)解法一(完全视作无向图的解法):def build_graph_set(edges): import collections graph

2020-09-17 05:28:28 21

原创 LeetCode题解(1379):找出指定节点在克隆二叉树中的相同节点(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)820ms (20.17%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)668ms (99.72%)Ans 3 (Python)解法一(深度优先搜索):class Solution: def getTargetCopy(self, origina

2020-09-17 05:28:23 46 1

原创 LeetCode题解(1372):计算二叉树中的最长交错路径的长度(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)492ms (74.21%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)532ms (55.66%)Ans 3 (Python)解法一:class Solution: def __init__(self): self.max =

2020-09-17 05:28:17 33

原创 LeetCode题解(1339):分裂一棵二叉树并使分裂成的两棵子树和的乘积最大(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)452ms (33.93%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)388ms (72.50%)Ans 3 (Python)解法一(两次遍历):class Solution: def __init__(self): self.

2020-09-17 05:28:13 124

原创 LeetCode题解(1325):删除二叉树中指定值的叶子节点(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)68ms (58.44%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def removeLeafNodes(self, root: TreeNode, target: int) -> TreeNode:

2020-09-17 05:28:07 49

原创 LeetCode题解(1315):计算二叉树中祖父节点值为偶数的节点和(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)124ms (59.48%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def sumEvenGrandparent(self, root: TreeNode, father=None, grandfather=None) -

2020-09-17 05:28:03 54

原创 LeetCode题解(1305):排序两棵二叉搜索树中的所有元素(Python)

题目:原题链接(中等)标签:树、二叉树、二叉搜索树、排序解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N1+N2)O(N1+N2)O(N1+N2)O(1)O(1)O(1)356ms (97.95%)Ans 2 (Python)O(N1+N2)O(N1+N2)O(N1+N2)O(1)O(1)O(1)372ms (90.64%)Ans 3 (Python)解法一(迭代器实现):def inorder_traversal_to_i

2020-09-16 06:01:37 30

原创 LeetCode题解(1302):二叉树中层数最深的所有叶子节点之和(Python)

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

2020-09-16 06:01:31 66

原创 LeetCode题解(1261):依据指定规则计算二叉树中的值并支持查找元素是否在二叉树中(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索、集合解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)108ms (73.17%)Ans 2 (Python)Ans 3 (Python)解法一:class FindElements: def __init__(self, root: TreeNode): self.lst = set()

2020-09-16 06:01:24 27

原创 LeetCode题解(1145):判断二叉树着色游戏是否有必胜策略(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)44ms (68.89%)Ans 2 (Python)Ans 3 (Python)解法一(深度优先搜索):class Solution: def __init__(self): self.choose_3 = -1 # 二号玩家选项3:一号玩家的右子节点

2020-09-16 06:01:17 38

原创 LeetCode题解(1123):计算二叉树中最深叶节点的最近公共祖先(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N×H)O(N×H)O(N×H)O(N)O(N)O(N)76ms (32.12%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)72ms (33.32%)Ans 3 (Python)O(N)O(N)O(N)O(N)O(N)O(N)56ms (92.23%)解法一:class Solution:

2020-09-16 06:01:10 25

原创 LeetCode题解(1110):删除二叉树中的指定点生成森林(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)100ms (30.00%)Ans 2 (Python)O(N)O(N)O(N)O(N)O(N)O(N)72ms (98.33%)Ans 3 (Python)解法一(深度优先搜索):class Solution: def __init__(self): self

2020-09-16 06:01:04 24

原创 LeetCode题解(1104):在Z字型完全二叉树中寻找到指定叶节点的路径(Python)

题目:原题链接(中等)标签:树、二叉树、数学解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)44ms (48.52%)Ans 2 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)44ms (48.52%)Ans 3 (Python)O(logN)O(logN)O(logN)O(1)O(1)O(1)40ms (73.70%)解法一:c

2020-09-16 06:00:59 18

原创 LeetCode题解(0037):解数独(Python)

题目:原题链接(困难)标签:数组、哈希表、回溯算法解法时间复杂度空间复杂度执行用时Ans 1 (Python)––536ms (23.19%)Ans 2 (Python)––196ms (61.74%)Ans 3 (Python)––72ms (96.28%)解法一(暴力的回溯算法):class Solution: def solveSudoku(self, board: List[List[str]]) -> None:

2020-09-16 06:00:53 17

原创 LeetCode题解(1028):依据已知深度的先序遍历还原二叉树(Python)

题目:原题链接(困难)标签:树、二叉树、深度优先搜索、字符串解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N×H)O(N×H)O(N×H) : 其中H为二叉树的深度O(N×H)O(N×H)O(N×H)92ms (73.93%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def recoverFromPreorder(self, S: str) -> TreeN

2020-09-16 06:00:47 29

原创 LeetCode题解(1026):计算结点与其任一祖先之间的最大差值(Python)

题目:原题链接(中等)标签:树、二叉树、深度优先搜索解法时间复杂度空间复杂度执行用时Ans 1 (Python)O(N)O(N)O(N)O(N)O(N)O(N)44ms (93.66%)Ans 2 (Python)Ans 3 (Python)解法一:class Solution: def __init__(self): self.ans = 0 def maxAncestorDiff(self, root:

2020-09-16 06:00:41 15

空空如也

空空如也

空空如也

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

TA关注的人 TA的粉丝

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