Skip to content

Commit b4c00cb

Browse files
authored
2210. count Hills and valleys in an Array
1 parent a44b806 commit b4c00cb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//................................
2+
int countHillValley(vector<int>& nums) {
3+
int ans = 0;
4+
int left = nums[0];
5+
6+
for(int i=1; i<nums.size()-1 ;i++)
7+
if(left < nums[i] && nums[i] > nums[i+1] || //Hill
8+
left > nums[i] && nums[i] < nums[i+1]){ //valeys
9+
ans++;
10+
left = nums[i];
11+
}
12+
return ans;
13+
}

0 commit comments

Comments
 (0)