五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

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

LeetCode 6911. Continuous Subarrays

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

You are given a?0-indexed?integer array?nums. A subarray of?nums?is called?continuous?if:

  • Let?i,?i + 1, ...,?j?be the indices in the subarray. Then, for each pair of indices?i <= i1, i2?<= j,?0 <=?|nums[i1] - nums[i2]| <= 2.

Return?the total number of?continuous?subarrays.

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

?

Example 1:

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

Output: 8

Explanation:?

Continuous subarray of size 1: [5], [4], [2], [4]. Continuous subarray of size 2: [5,4], [4,2], [2,4]. Continuous subarray of size 3: [4,2,4]. Thereare no subarrys of size 4. Total continuous subarrays = 4 + 3 + 1 = 8. It can be shown that there are no more continuous subarrays.

?

Example 2:

Input: nums = [1,2,3]

Output: 6

Explanation: Continuous subarray of size 1: [1], [2], [3]. Continuous subarray of size 2: [1,2], [2,3]. Continuous subarray of size 3: [1,2,3]. Total continuous subarrays = 3 + 2 + 1 = 6.

?

Constraints:

  • 1 <= nums.length <= 105

  • 1 <= nums[i] <= 109

這里利用雙指針以及優(yōu)先隊(duì)列來存儲最大值最小值,只是我考慮的時(shí)候,以為存在相同元素的話,不好實(shí)現(xiàn),結(jié)果還是能實(shí)現(xiàn),下面是代碼:(j-i+1是以i為開頭的所有可能的子數(shù)組的數(shù)量)-我有1個(gè)for循環(huán)+while循環(huán)在周賽的時(shí)候也過了呀,過了周賽就TLE了。。。

Runtime:?296 ms, faster than?25.00%?of?Java?online submissions for?Continuous Subarrays.

Memory Usage:?58.4 MB, less than?25.00%?of?Java?online submissions for?Continuous Subarrays.


LeetCode 6911. Continuous Subarrays的評論 (共 條)

分享到微博請遵守國家法律
岗巴县| 沁源县| 元谋县| 西林县| 蒙阴县| 晋城| 建湖县| 铜川市| 文山县| 郸城县| 简阳市| 阜阳市| 长垣县| 广元市| 六安市| 清新县| 北碚区| 宁晋县| 邳州市| 临武县| 广东省| 桃江县| 和平县| 班玛县| 阿克陶县| 太白县| 海兴县| 保定市| 介休市| 侯马市| 陵川县| 田阳县| 定陶县| 石台县| 伊宁县| 昆明市| 白银市| 闻喜县| 乌恰县| 女性| 堆龙德庆县|