中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

動態(tài)網(wǎng)站沒有數(shù)據(jù)庫怎么做產(chǎn)品推廣策劃書

動態(tài)網(wǎng)站沒有數(shù)據(jù)庫怎么做,產(chǎn)品推廣策劃書,呢圖網(wǎng)站場建設(shè)封面,鄭州seo詢搜點網(wǎng)絡(luò)效果佳給你一個二叉樹的根節(jié)點 root ,判斷其是否是一個有效的二叉搜索樹。 有效 二叉搜索樹定義如下: 節(jié)點的左子樹 只包含 小于 當前節(jié)點的數(shù)。 節(jié)點的右子樹只包含 大于 當前節(jié)點的數(shù)。 所有左子樹和右子樹自身必須也是二叉搜索樹。 英文題目 Given the root…

給你一個二叉樹的根節(jié)點 root ,判斷其是否是一個有效的二叉搜索樹。
有效 二叉搜索樹定義如下:
節(jié)點的左子樹
只包含 小于 當前節(jié)點的數(shù)。
節(jié)點的右子樹只包含 大于 當前節(jié)點的數(shù)。
所有左子樹和右子樹自身必須也是二叉搜索樹。

英文題目
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
A valid BST is defined as follows:
The left subtreeof a node contains only nodes with keys less than the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
Both the left and right subtrees must also be binary search trees.

解題思路

畫了一個四層的二叉樹,發(fā)現(xiàn)遞歸方法是,左子樹的最右節(jié)點應(yīng)該比根節(jié)點小,右子樹的最左節(jié)點應(yīng)該比根節(jié)點大,基于此寫的代碼(事實上只要想著所有點,然后更新邊界,就可以不用重復(fù)遍歷來遞歸了)

AC代碼

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:def isValidBST(self, root: Optional[TreeNode]) -> bool:def judge(root):if root.left is None and root.right is None:return Trueif root is None:return Trueleft, right, leftflag, rightflag = root.left, root.right, True, Trueif left is not None:while left.right is not None:left = left.rightleftflag = root.val > left.val and judge(root.left)if right is not None:while right.left is not None:right = right.leftrightflag = root.val < right.val and judge(root.right)return  leftflag and rightflagreturn judge(root)

官方題解

想到使用邊界后面思路就一下子通了

class Solution:def isValidBST(self, root: TreeNode) -> bool:stack, inorder = [], float('-inf')while stack or root:while root:stack.append(root)root = root.leftroot = stack.pop()# 如果中序遍歷得到的節(jié)點的值小于等于前一個 inorder,說明不是二叉搜索樹if root.val <= inorder:return Falseinorder = root.valroot = root.rightreturn True
http://www.risenshineclean.com/news/23320.html

相關(guān)文章:

  • dw網(wǎng)頁設(shè)計制作網(wǎng)站的成品自己創(chuàng)建網(wǎng)頁
  • 無錫高端網(wǎng)站建設(shè)開發(fā)在線咨詢 1 網(wǎng)站宣傳
  • 快設(shè)計網(wǎng)站官網(wǎng)seo國外英文論壇
  • b2b跟b2c有什么區(qū)別seo網(wǎng)上培訓課程
  • 做網(wǎng)站一定要后臺嘛網(wǎng)站建設(shè)優(yōu)化400報價
  • 廈門網(wǎng)站建設(shè)哪家好小程序制作
  • 鞍山疫情最新情況鄭州網(wǎng)站seo公司
  • 做網(wǎng)站的目標是什么福鼎網(wǎng)站優(yōu)化公司
  • nas服務(wù)器 做網(wǎng)站域名大全免費網(wǎng)站
  • wordpress多大伊春seo
  • 武漢微信網(wǎng)站建設(shè)網(wǎng)站seo推廣員招聘
  • 如何做商業(yè)推廣網(wǎng)站淘寶搜索排名
  • 做外貿(mào)家紡資料網(wǎng)站重慶店鋪整站優(yōu)化
  • 關(guān)于做花茶網(wǎng)站的策劃書windows優(yōu)化大師有必要安裝嗎
  • 哈爾濱 微網(wǎng)站設(shè)計百度站長工具
  • 政府網(wǎng)站建設(shè)開題報告企業(yè)網(wǎng)站怎么制作
  • 個人免費網(wǎng)站注冊seo整站優(yōu)化服務(wù)
  • 在線代碼編輯器seo 優(yōu)化案例
  • 音樂網(wǎng)站開發(fā)分享企拓客軟件怎么樣
  • 如何給自己網(wǎng)站做反鏈全國今日新增疫情
  • 網(wǎng)站制作設(shè)計方案行業(yè)網(wǎng)站網(wǎng)址
  • 天津外貿(mào)網(wǎng)站建設(shè)阿里云域名注冊流程
  • 十堰網(wǎng)站建設(shè)公司公司品牌推廣方案范文
  • 托管型網(wǎng)站專業(yè)網(wǎng)絡(luò)推廣公司排名
  • wordpress4.0 中文深圳專業(yè)seo
  • 有哪些做海島的網(wǎng)站seo推廣主要做什么
  • 模板制作方法重慶seo網(wǎng)頁優(yōu)化
  • 想做一個自己的網(wǎng)站 怎么做北京谷歌優(yōu)化
  • 網(wǎng)站服務(wù)器提供商北京seo顧問推推蛙
  • 圖書信息管理系統(tǒng)代碼網(wǎng)站建設(shè)seo搜索引擎優(yōu)化哪家好