3350. 检测相邻递增子数组 II

题目链接:https://leetcode.cn/problems/adjacent-increasing-subarrays-detection-ii/
题解代码:

int maxIncreasingSubarrays(int* nums, int numsSize) {
    int ans = 0, pre_cnt = 0,cnt=0;
    for(int i=0;i<numsSize;i++){
        cnt++;
        if(i==numsSize-1||nums[i]>=nums[i+1]){
            int min_ = (pre_cnt>cnt) ?cnt:pre_cnt,
                max_ = (ans > cnt/2) ? ans : cnt/2;
                ans = (max_ >min_ ) ? max_ : min_;
                pre_cnt =cnt;
                cnt=0;
        }
    }
    return ans;
}
posted @ 2024-11-14 00:31  fufuaifufu  阅读(12)  评论(0编辑  收藏  举报