首页 > 其他 > 详细

941. Valid Mountain Array

时间:2020-07-15 01:34:09      阅读:67      评论:0      收藏:0      [点我收藏+]

Given an array A of integers, return true if and only if it is a valid mountain array.

Recall that A is a mountain array if and only if:

  • A.length >= 3
  • There exists some i with 0 < i < A.length - 1 such that:
    • A[0] < A[1] < ... A[i-1] < A[i]
    • A[i] > A[i+1] > ... > A[A.length - 1]
      判断一个数组是不是山峰数组,就是先严格递增然后严格递减,不能相等
      class Solution(object):
          def validMountainArray(self, A):
              """
              :type A: List[int]
              :rtype: bool
              """
              index = 1
              n = len(A)
              while index < n and A[index] > A[index - 1]:
                  index += 1
              if index == 1 or index == n:
                  return False
              while index < n and A[index] < A[index - 1]:
                  index += 1
              return index == n
                          

       

941. Valid Mountain Array

原文:https://www.cnblogs.com/whatyouthink/p/13302877.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!