无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 6909. Longest Even Odd Subarray With Threshold

2023-07-02 12:53 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?integer array?nums?and an integer?threshold.

Find the length of the?longest subarray?of?nums?starting at index?l?and ending at index?r?(0 <= l <= r < nums.length)?that satisfies the following conditions:

  • nums[l] % 2 == 0

  • For all indices?i?in the range?[l, r - 1],?nums[i] % 2 != nums[i + 1] % 2

  • For all indices?i?in the range?[l, r],?nums[i] <= threshold

Return?an integer denoting the length of the longest such subarray.

Note:?A?subarray?is a contiguous non-empty sequence of elements within an array.

?

Example 1:

Input: nums = [3,2,5,4], threshold = 5

Output: 3

Explanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions. Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.

Example 2:

Input: nums = [1,2], threshold = 2

Output: 1

Explanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2]. It satisfies all the conditions and we can show that 1 is the maximum possible achievable length.

Example 3:

Input: nums = [2,3,4,5], threshold = 4

Output: 3

Explanation: In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4]. It satisfies all the conditions. Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.

?

Constraints:

  • 1 <= nums.length <= 100

  • 1 <= nums[i] <= 100

  • 1 <= threshold <= 100

周賽的題目;卡了一下,沒(méi)有考慮長(zhǎng)度為1 的情況;

Runtime:?15 ms, faster than?33.33%?of?Java?online submissions for?Longest Even Odd Subarray With Threshold.

Memory Usage:?43.6 MB, less than?100.00%?of?Java?online submissions for?Longest Even Odd Subarray With Threshold.


LeetCode 6909. Longest Even Odd Subarray With Threshold的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
和政县| 烟台市| 思茅市| 景宁| 鄂温| 龙游县| 盐池县| 德庆县| 萝北县| 崇左市| 武宣县| 门头沟区| 阿合奇县| 新绛县| 沈阳市| 临高县| 宁河县| 莱西市| 广东省| 修武县| 闽侯县| 延津县| 东乡族自治县| 晋宁县| 吉木乃县| 侯马市| 望城县| 上栗县| 永平县| 遂昌县| 彭泽县| 衡东县| 博乐市| 安溪县| 张掖市| 关岭| 高青县| 泰宁县| 清流县| 江口县| 凭祥市|