当前位置: 首页 > wzjs >正文

免费网站安全软件2023年国内十大新闻

免费网站安全软件,2023年国内十大新闻,微信开放平台电话,进口商品代理平台目录 一、二叉树 1. 二叉树的深度遍历(DFS:前序、中序、后序遍历) 2. 二叉树的最大深度 3. 翻转二叉树 4. 对称二叉树 5. 二叉树的直径 6. 二叉树的层序遍历 7. 将有序数组转换为二叉搜索树 8. 验证二叉搜索树 9. 二叉搜索树中第 K 小的元素 …

目录

一、二叉树

1. 二叉树的深度遍历(DFS:前序、中序、后序遍历)

2. 二叉树的最大深度

3. 翻转二叉树

4. 对称二叉树

5. 二叉树的直径

6. 二叉树的层序遍历

7. 将有序数组转换为二叉搜索树

8. 验证二叉搜索树

9. 二叉搜索树中第 K 小的元素

10. 二叉树的右视图

(待更...)

二、图论(待更...)


前言

一、二叉树:二叉树的中序遍历,二叉树的最大深度,翻转二叉树,对称二叉树,二叉树的直径,二叉树的层序遍历,将有序数组转换为二叉搜索树,验证二叉搜索树,二叉搜索树中第 K 小的元素,二叉树的右视图...... (日更ing)

二、图论:...... (日更ing)


一、二叉树

1. 二叉树的深度遍历(DFS:前序、中序、后序遍历)

 原题链接:94. 二叉树的中序遍历 - 力扣(LeetCode)

# (1)前序遍历:根-左-右
class Solution(object):def preorderTraversal(self, root):res = []def preorder(root):if not root:return res.append(root.val)preorder(root.left)preorder(root.right)preorder(root)return res
# (2)中序遍历:左-根-右
class Solution(object):def inorderTraversal(self, root):res = []def inorder(root):if not root:return inorder(root.left)res.append(root.val)inorder(root.right)inorder(root)return res

# (3)后序遍历:左-右-根
class Solution(object):def postorderTraversal(self, root):res = []def inorder(root):if not root:return postorder(root.left)postorder(root.right)res.append(root.val)postorder(root)return res

2. 二叉树的最大深度

原题链接:104. 二叉树的最大深度 - 力扣(LeetCode)

class Solution(object):def maxDepth(self, root):if not root:return 0left_height = self.maxDepth(root.left)right_height = self.maxDepth(root.right)return max(left_height, right_height) + 1

3. 翻转二叉树

原题链接:226. 翻转二叉树 - 力扣(LeetCode)

class Solution(object):def invertTree(self, root):if not root:return root.left, root.right = root.right, root.leftself.invertTree(root.left)self.invertTree(root.right)return root

4. 对称二叉树

原题链接:101. 对称二叉树 - 力扣(LeetCode)

class Solution(object):def isSymmetric(self, root):def check(left, right):if not left and not right:return Trueif not left or not right:return Falseif left.val != right.val:return Falsereturn check(left.left, right.right) and check(left.right, right.left)return check(root.left, root.right)

5. 二叉树的直径

原题链接:543. 二叉树的直径 - 力扣(LeetCode)

class Solution(object):def diameterOfBinaryTree(self, root):def dfs(root):if not root:return 0, 0ld, ldepth = dfs(root.left)rd, rdepth = dfs(root.right)return max(ld, rd, ldepth+rdepth), max(ldepth, rdepth) + 1return dfs(root)[0]

6. 二叉树的层序遍历

原题链接:102. 二叉树的层序遍历 - 力扣(LeetCode)

class Solution(object):def levelOrder(self, root):if not root:return []node = [root]res = []while len(node) > 0:res.append([i.val for i in node])node2 = []for i in node:if i.left:node2.append(i.left)if i.right:node2.append(i.right)node = node2return res

7. 将有序数组转换为二叉搜索树

原题链接:108. 将有序数组转换为二叉搜索树 - 力扣(LeetCode)

class Solution(object):def sortedArrayToBST(self, nums):def dfs(left, right):if left > right:returnmid = (left + right) // 2root = TreeNode(nums[mid])root.left = dfs(left, mid-1)root.right = dfs(mid+1, right)return rootreturn dfs(0, len(nums)-1)

8. 验证二叉搜索树

原题链接:98. 验证二叉搜索树 - 力扣(LeetCode)

class Solution(object):def isValidBST(self, root, left=float('-inf'), right=float('inf')):if not root:return Truex = root.valreturn left < x < right and self.isValidBST(root.left, left, x) and self.isValidBST(root.right, x, right)
# self.isValidBST(root.left, left, x):遍历左子树,右边界更新
# self.isValidBST(root.right, x, right):遍历右子树,左边界更新

9. 二叉搜索树中第 K 小的元素

原题链接:230. 二叉搜索树中第 K 小的元素 - 力扣(LeetCode)

# 先通过前序/中序/后序遍历转为list,而后利用list属性找第k个小的元素。
# 此代码使用前序遍历(根-左-右)
class Solution(object):def kthSmallest(self, root, k):res = [] def preorder(root):if not root:returnres.append(root.val)preorder(root.left)preorder(root.right)return resres = preorder(root)res.sort()return res[k-1]

10. 二叉树的右视图

原题链接:199. 二叉树的右视图 - 力扣(LeetCode)

class Solution(object):def rightSideView(self, root):# if len(res) == depth: res.append(root.val)# 先遍历右子树,再遍历左子树res = []def dfs(root, depth):if not root:return []if len(res) == depth:res.append(root.val)dfs(root.right, depth+1)dfs(root.left, depth+1)return resreturn dfs(root, 0)


二、图论


文章转载自:

http://wHKJfygD.yrngx.cn
http://AmqUYkwN.yrngx.cn
http://E9OCXYww.yrngx.cn
http://19k1LZbM.yrngx.cn
http://wn71UIVl.yrngx.cn
http://Uh6fAIOp.yrngx.cn
http://FJHNtu5t.yrngx.cn
http://j9NewCpn.yrngx.cn
http://I2plvKfk.yrngx.cn
http://kO2LBQEC.yrngx.cn
http://iYIxB0rY.yrngx.cn
http://ScsMCOl2.yrngx.cn
http://4IctxMzt.yrngx.cn
http://7VJ84FrT.yrngx.cn
http://e3pBKwoG.yrngx.cn
http://tPUA4LEz.yrngx.cn
http://aS3fz1qL.yrngx.cn
http://wrpfFCfS.yrngx.cn
http://AjHNT8c2.yrngx.cn
http://VVueudAY.yrngx.cn
http://IH5zAjQy.yrngx.cn
http://ZQqeWZdh.yrngx.cn
http://wsttNlSv.yrngx.cn
http://IBjB81Os.yrngx.cn
http://MBKA3sby.yrngx.cn
http://DPkQ3j65.yrngx.cn
http://advf2pRZ.yrngx.cn
http://YuO37P1m.yrngx.cn
http://T19quemX.yrngx.cn
http://c7bkxrkK.yrngx.cn
http://www.dtcms.com/wzjs/672446.html

相关文章:

  • 如何做网站专题网站建站方式有哪些
  • django校园网站开发科技公司 网站 石家庄
  • 哈尔滨城市建设局网站网站没有关键词库
  • 东莞网站seo方法wordpress导航菜单图标
  • 免费网站论坛做做网
  • 专做女鞋的网站代发广州视频软件下载大全免费
  • 免备案自助建站网站中国十大软件开发公司排名
  • 南京建设网站哪家好申请专利的网站
  • 东阳网站建设怎么选义乌创源网站建设
  • 集团网站目标有关电商网站开发的参考文献
  • 南通城乡建设局网站首页山东三强建设咨询有限公司网站
  • 如何申请自己的网站网站速度怎么提升
  • 网站后台添加文章后怎么不显示做签名照的网站
  • 外贸网站建设公司渠道保健品网站怎么做的
  • 政协网站建设情况汇报中国能源建设集团网站群
  • 亚马逊一般在哪些网站上做推广平台设计方案
  • wordpress建站网站建设多少钱比较合适
  • 那些网站是php做的高端的网站建设怎么做
  • 建立一个自己的网站网站建站业务
  • 中国做贸易的网站手机登录凡科网
  • 网站图片设置隐私保护怎么下载吴江seo
  • 国内做led灯网站有静态网站如何共用一个头部和尾部
  • 社区类网站建设十大免费跨境电商平台
  • 上海电商设计招聘网站电子商务网站的建设心得体会
  • 网站建设的建议网站建设服务合同要交印花税吗
  • 承德网站建设制作iis wordpress rewrite
  • 网站开发进度计划是什么php做网站流程
  • 精通网站开发衡水手机网站建设价格
  • 衡水网站优化推广苏州外贸网站制作公司
  • 单位加强网站建设建设部网站退休注册人员