{"id":228,"date":"2018-09-15T19:44:04","date_gmt":"2018-09-15T11:44:04","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=228"},"modified":"2018-11-29T14:44:43","modified_gmt":"2018-11-29T06:44:43","slug":"852-peak-index-in-a-mountain-array","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=228","title":{"rendered":"852. Peak Index in a Mountain Array"},"content":{"rendered":"<p>Let&#8217;s call an array\u00a0<code>A<\/code>\u00a0a\u00a0<em>mountain<\/em>\u00a0if the following properties hold:<\/p>\n<ul>\n<li><code>A.length &gt;= 3<\/code><\/li>\n<li>There exists some\u00a0<code>0 &lt; i\u00a0&lt; A.length - 1<\/code>\u00a0such that\u00a0<code>A[0] &lt; A[1] &lt; ... A[i-1] &lt; A[i] &gt; A[i+1] &gt; ... &gt; A[A.length - 1]<\/code><\/li>\n<\/ul>\n<p>Given an array that is definitely a mountain, return any\u00a0<code>i<\/code>\u00a0such that\u00a0<code>A[0] &lt; A[1] &lt; ... A[i-1] &lt; A[i] &gt; A[i+1] &gt; ... &gt; A[A.length - 1]<\/code>.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input: <\/strong><span id=\"example-input-1-1\">[0,1,0]<\/span>\r\n<strong>Output: <\/strong><span id=\"example-output-1\">1<\/span>\r\n<\/pre>\n<div>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input: <\/strong><span id=\"example-input-2-1\">[0,2,1,0]<\/span>\r\n<strong>Output: <\/strong><span id=\"example-output-2\">1<\/span><\/pre>\n<\/div>\n<p><strong>Note:<\/strong><\/p>\n<ol>\n<li><code>3 &lt;= A.length &lt;= 10000<\/code><\/li>\n<li><code><span style=\"font-family: monospace;\">0 &lt;= A[i] &lt;= 10^6<\/span><\/code><\/li>\n<li>A\u00a0is a mountain, as defined above.<\/li>\n<\/ol>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def peakIndexInMountainArray(self, A):\r\n        &quot;&quot;&quot;\r\n        :type A: List[int]\r\n        :rtype: int\r\n        &quot;&quot;&quot;\r\n        index = 0\r\n        for i in A:\r\n            if i &gt; A[index + 1]:\r\n                return index\r\n            else:\r\n                index += 1\r\n            \r\n        \r\n        \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s call an array\u00a0A\u00a0a\u00a0mountain\u00a0if the following<a href=\"https:\/\/www.ccagml.com\/?p=228\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">852. Peak Index in a Mountain Array<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/228"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":229,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions\/229"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}