Skip to content

Commit e920d7d

Browse files
committed
0941 added.
1 parent 646d496 commit e920d7d

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(A)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
6+
add_executable(A main.cpp)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// Source : https://leetcode.com/problems/valid-mountain-array/
2+
/// Author : liuyubobobo
3+
/// Time : 2018-11-17
4+
5+
#include <iostream>
6+
#include <vector>
7+
8+
using namespace std;
9+
10+
11+
/// One Pass
12+
/// Time Complexity: O(n)
13+
/// Space Complexity: O(1)
14+
class Solution {
15+
public:
16+
bool validMountainArray(vector<int>& A) {
17+
18+
if(A.size() < 3)
19+
return false;
20+
21+
int i;
22+
for(i = 1; i < A.size(); i ++)
23+
if(A[i] < A[i - 1])
24+
break;
25+
else if(A[i] == A[i - 1])
26+
return false;
27+
28+
if(i == 1 || i == A.size())
29+
return false;
30+
31+
for(int j = i; j < A.size(); j ++)
32+
if(A[j - 1] <= A[j])
33+
return false;
34+
35+
return true;
36+
}
37+
};
38+
39+
40+
int main() {
41+
42+
vector<int> A1 = {0, 3, 2, 1};
43+
cout << Solution().validMountainArray(A1) << endl;
44+
// true
45+
46+
return 0;
47+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,4 +596,5 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
596596
| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst/) | [solution](https://leetcode.com/problems/range-sum-of-bst/solution/) | [C++](0938-Range-Sum-of-BST/cpp-0938/) | | |
597597
| 939 | [Minimum Area Rectangle](https://leetcode.com/problems/minimum-area-rectangle/) | [solution](https://leetcode.com/problems/minimum-area-rectangle/solution/) | [C++](0939-Minimum-Area-Rectangle/cpp-0939/) | | |
598598
| 940 | [Distinct Subsequences II](https://leetcode.com/problems/distinct-subsequences-ii/) | [solution](https://leetcode.com/problems/distinct-subsequences-ii/solution/) | [C++](0940-Distinct-Subsequences-II/cpp-0940/) | | |
599+
| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array/) | [solution](https://leetcode.com/problems/valid-mountain-array/solution/) | [C++](0941-Valid-Mountain-Array/cpp-0941/) | | |
599600
| | | | | | |

0 commit comments

Comments
 (0)