Problem: 2210. 统计数组中峰和谷的数量 Code class Solution {public:int countHillValley(vector<int>& nums) {int cnt = 0;int n = nums.size();for(int i = 1; i < n - 1; i ++) {// if(nums[i] > nums[i + 1] && num
题目链接: 力扣https://leetcode-cn.com/problems/count-hills-and-valleys-in-an-array/ 【分析】先遍历一遍在原数组上去重,然后根据要求找就行了。 class Solution {public int countHillValley(int[] nums) {int n = nums.length;int i, m = 1