别怕麻烦,模拟题有时候就是要多写一些条件(或者你思维很活跃找出规律),代码如下:
class Solution {
public:int temperatureTrend(vector<int>& temperatureA, vector<int>& temperatureB) {int n = temperatureA.size(),ans = 0,k = 0;for(int i=0;i<n-1;i++){if(temperatureA[i] < temperatureA[i+1] && temperatureB[i] < temperatureB[i+1] || temperatureA[i] == temperatureA[i+1] && temperatureB[i] == temperatureB[i+1] || temperatureA[i] > temperatureA[i+1] && temperatureB[i] > temperatureB[i+1]){k ++;ans = max(ans,k);}else k = 0;}return ans;}
};
加油