LC 气温变化趋势

简单的开篇。

#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
	int temperatureTrend(vector<int>& temperatureA, vector<int>& temperatureB) {
		int length = temperatureA.size();
		int maxTend = 0, tendNow = 0;
		auto GetTodayTend = [&](int gap) {
			if (gap == 0)return 0;
			return gap > 0 ? 1 : -1;
		};
		for (int i = 1; i < length; i++)
		{
			bool isDaySame = GetTodayTend(temperatureA[i] - temperatureA[i - 1]) == GetTodayTend(temperatureB[i] - temperatureB[i - 1]);
			if (isDaySame) {
				++tendNow;
				maxTend = max(maxTend, tendNow);
			}
			else {
				tendNow = 0;
			}
		}
		return maxTend;
	}
};
posted @ 2024-06-24 21:03  vil4  阅读(7)  评论(0)    收藏  举报