2023每日刷题(三十一)
Leetcode—2760.最长奇偶子数组
实现代码
#define MAX(a, b) ((a > b) ? (a): (b))
int longestAlternatingSubarray(int* nums, int numsSize, int threshold){int ans = 0;int i = 0;while(i < numsSize) {if(nums[i] > threshold || nums[i] % 2) {i++;continue;}int start = i;i++;while(i < numsSize && nums[i] <= threshold && nums[i] % 2 != nums[i - 1] % 2) {i++;}ans = MAX(ans, i - start);}return ans;
}
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!