Leetcode-941 Valid Mountain Array(有效的山脉数组)

 1 class Solution
 2 {
 3     public:
 4         bool validMountainArray(vector<int>& A)
 5         {
 6             if(A.size()<3)
 7                 return false;
 8             int maxIndex;
 9             
10             for(int i = 0;i < A.size();i ++)
11             {
12                 if(A[i]>A[maxIndex])
13                     maxIndex = i;
14             }
15             if(maxIndex==A.size()-1||maxIndex==0)
16                 return false;
17             for(int i = 0;i < maxIndex;i ++)
18             {
19                 if(A[i]>=A[i+1])
20                     return false;
21             }
22             for(int i = maxIndex;i < A.size()-1;i ++)
23             {
24                 if(A[i]<=A[i+1])
25                     return false;
26             }
27             return true;
28         }
29 };
原文地址:https://www.cnblogs.com/Asurudo/p/9977560.html