-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstable_mountains.cpp
More file actions
52 lines (47 loc) · 1.37 KB
/
stable_mountains.cpp
File metadata and controls
52 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* =====================================================================================
*
* Filename: stable_mountains.cpp
*
* Description: 3285. Find Indices of Stable Mountains
*
* Version: 1.0
* Created: 09/22/2024 15:26:40
* Revision: none
* Compiler: gcc
*
* Author: xianfeng.zhu@gmail.com
* Organization:
*
* =====================================================================================
*/
#include <tuple>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using std::tuple;
using std::vector;
class Solution {
public:
vector<int> stableMountains(vector<int>& height, int threshold) {
vector<int> indices;
indices.reserve(height.size());
for (int i = 1; i < height.size(); i++) {
if (height[i - 1] > threshold) {
indices.push_back(i);
}
}
return indices;
}
};
TEST(Solution, stableMountains) {
vector<tuple<vector<int>, int, vector<int>>> cases = {
std::make_tuple(vector<int>{1, 2, 3, 4, 5}, 2, vector<int>{3, 4}),
std::make_tuple(vector<int>{10, 1, 10, 1, 10}, 3, vector<int>{1, 3}),
std::make_tuple(vector<int>{10, 1, 10, 1, 10}, 10, vector<int>{}),
};
for (auto& c : cases) {
EXPECT_THAT(Solution().stableMountains(std::get<0>(c), std::get<1>(c)),
testing::ElementsAreArray(std::get<2>(c)));
}
}