{"id":2496,"date":"2022-02-02T11:56:05","date_gmt":"2022-02-02T03:56:05","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2496"},"modified":"2022-02-02T11:56:07","modified_gmt":"2022-02-02T03:56:07","slug":"leetcodeday98","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday98\/","title":{"rendered":"leetcodeday98 &#8211;\u9a8c\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;<code>root<\/code>&nbsp;\uff0c\u5224\u65ad\u5176\u662f\u5426\u662f\u4e00\u4e2a\u6709\u6548\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002<\/p>\n\n\n\n<p><strong>\u6709\u6548<\/strong>&nbsp;\u4e8c\u53c9\u641c\u7d22\u6811\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>\u8282\u70b9\u7684\u5de6\u5b50\u6811\u53ea\u5305\u542b<strong>&nbsp;\u5c0f\u4e8e&nbsp;<\/strong>\u5f53\u524d\u8282\u70b9\u7684\u6570\u3002<\/li><li>\u8282\u70b9\u7684\u53f3\u5b50\u6811\u53ea\u5305\u542b&nbsp;<strong>\u5927\u4e8e<\/strong>&nbsp;\u5f53\u524d\u8282\u70b9\u7684\u6570\u3002<\/li><li>\u6240\u6709\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u81ea\u8eab\u5fc5\u987b\u4e5f\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=98 lang=python3\r\n#\r\n# &#91;98] \u9a8c\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811\r\n#\r\n\r\n# @lc code=start\r\n# Definition for a binary tree node.\r\n# class TreeNode:\r\n#     def __init__(self, val=0, left=None, right=None):\r\n#         self.val = val\r\n#         self.left = left\r\n#         self.right = right\r\nclass Solution:\r\n    def isValidBST(self, root: TreeNode) -> bool:\r\n        nums=&#91;]\r\n        def isValid(root):\r\n\r\n            if root == None:\r\n                return \r\n            \r\n            isValid(root.left)\r\n            nums.append(root.val)    \r\n            isValid(root.right)\r\n        isValid(root)\r\n        for i in range(len(nums)-1):\r\n            j=i+1\r\n            if nums&#91;i]>=nums&#91;j]:\r\n                return False\r\n            \r\n        return True\r\n\r\n\r\n                \r\n# @lc code=end<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"859\" height=\"217\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image.png\" alt=\"\" class=\"wp-image-2499\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image.png 859w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-300x76.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-768x194.png 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=98 lang=python3\r\n#\r\n# &#91;98] \u9a8c\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811\r\n#\r\n\r\n# @lc code=start\r\n# Definition for a binary tree node.\r\n# class TreeNode:\r\n#     def __init__(self, val=0, left=None, right=None):\r\n#         self.val = val\r\n#         self.left = left\r\n#         self.right = right\r\nclass Solution:\r\n    def isValidBST(self, root: TreeNode) -> bool:\r\n        nums=&#91;-2**31-1]\r\n        def isValid(root):\r\n            if root == None:\r\n                return True\r\n            if isValid(root.left)==False:\r\n                return False\r\n            if root.val > nums&#91;0]:\r\n                nums&#91;0]= root.val\r\n            else: \r\n                return False\r\n            if isValid(root.right)==False:\r\n                return False\r\n        return isValid(root) if isValid(root)==False else True\r\n\r\n\r\n\r\n                \r\n# @lc code=end<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"820\" height=\"211\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-1.png\" alt=\"\" class=\"wp-image-2500\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-1.png 820w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-1-300x77.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-1-768x198.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;root&nbsp;\uff0c\u5224\u65ad\u5176\u662f\u5426\u662f\u4e00\u4e2a\u6709\u6548\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002 \u6709\u6548&nbsp;\u4e8c &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday98\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday98 &#8211;\u9a8c\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2496"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2496"}],"version-history":[{"count":3,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2496\/revisions"}],"predecessor-version":[{"id":2501,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2496\/revisions\/2501"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2496"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}