{"id":729,"date":"2020-09-26T11:15:23","date_gmt":"2020-09-26T03:15:23","guid":{"rendered":"http:\/\/39.96.58.60\/?p=729"},"modified":"2022-10-18T16:37:28","modified_gmt":"2022-10-18T08:37:28","slug":"leetcode-941-%e6%9c%89%e6%95%88%e7%9a%84%e5%b1%b1%e8%84%89%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=729","title":{"rendered":"Leetcode 941. \u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4"},"content":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>A<\/code>\uff0c\u5982\u679c\u5b83\u662f\u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4\u5c31\u8fd4\u56de&nbsp;<code>true<\/code>\uff0c\u5426\u5219\u8fd4\u56de <code>false<\/code>\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u56de\u987e\u4e00\u4e0b\uff0c\u5982\u679c A \u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\uff0c\u90a3\u4e48\u5b83\u662f\u4e00\u4e2a\u5c71\u8109\u6570\u7ec4\uff1a<\/p>\n<ul>\n<li><code>A.length &gt;= 3<\/code><\/li>\n<li>\u5728&nbsp;<code>0 &lt; i&nbsp;&lt; A.length - 1<\/code>&nbsp;\u6761\u4ef6\u4e0b\uff0c\u5b58\u5728&nbsp;<code>i<\/code>&nbsp;\u4f7f\u5f97\uff1a\n<ul>\n<li><code>A[0] &lt; A[1] &lt; ... A[i-1] &lt; A[i] <\/code><\/li>\n<li><code>A[i] &gt; A[i+1] &gt; ... &gt; A[A.length - 1]<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><img alt=\"\" src=\"https:\/\/assets.leetcode.com\/uploads\/2019\/10\/20\/hint_valid_mountain_array.png\" style=\"height: 316px; width: 500px;\"><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>[2,1]\n\n<strong>\u8f93\u51fa\uff1a<\/strong>false\n\n<\/pre>\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>[3,5,5]\n\n<strong>\u8f93\u51fa\uff1a<\/strong>false\n\n<\/pre>\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>[0,3,2,1]\n\n<strong>\u8f93\u51fa\uff1a<\/strong>true<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ol>\n<li><code>0 &lt;= A.length &lt;= 10000<\/code><\/li>\n<li><code>0 &lt;= A[i] &lt;= 10000&nbsp;<\/code><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>**\u96be\u5ea6**: Easy<\/p>\n<p>**\u6807\u7b7e**: \u6570\u7ec4\u3001<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code>\n# -*- coding: utf-8 -*-\n# @Author  : LG\n\n\"\"\"\n\u6267\u884c\u7528\u65f6\uff1a236 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8693.30% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a15 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e869.53% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u5177\u4f53\u5b9e\u73b0\u89c1\u4ee3\u7801\u6ce8\u91ca\n\"\"\"\nclass Solution:\n    def validMountainArray(self, A: List[int]) -&gt; bool:\n        if len(A) &lt; 3:  # \u5982\u679c\u957f&lt;3\uff0cFalse\n            return False\n        if not (A[0] &lt; A[1] and A[-1] &lt; A[-2]): # \u5224\u65ad\u8d77\u59cb\u4e0e\u7ed3\u5c3e\uff0c\u5982\u4e0d\u6ee1\u8db3\u5219\u76f4\u63a5False\n            return False\n\n        up = True   # \u8bb0\u5f55\u4e0a\u5347\u72b6\u6001\n        for i in range(1, len(A)):\n            if A[i] &gt; A[i-1] and up:    # \u5982\u679c\u5f53\u524d\u4e0a\u5347\uff0c\u5219\u8df3\u8fc7\n                pass\n            elif A[i] &lt; A[i-1]: # \u5982\u679c\u5f53\u524d\u4e0b\u964d\uff0c\u5219\u5c06\u72b6\u6001\u81f3\u4e8e\u4e0b\u964d\n                up = False\n            else:   # \u5982\u679c\u4e0b\u964d\u72b6\u6001\uff0c\u4f46\u6570\u503c\u589e\u5927\uff0c\u6216\u6570\u503c\u4e0d\u53d8\uff0c\u5219False\n                return False\n        return True<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;A\uff0c\u5982\u679c\u5b83\u662f\u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4\u5c31\u8fd4\u56de&nbsp;true\uff0c\u5426\u5219\u8fd4\u56de false\u3002 \u8ba9\u6211&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/729"}],"collection":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=729"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/729\/revisions"}],"predecessor-version":[{"id":730,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/729\/revisions\/730"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=729"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}