最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
霍城县| 徐水县| 鹤庆县| 甘肃省| 永新县| 沅陵县| 永登县| 嘉祥县| 济阳县| 宿州市| 普陀区| 商都县| 阿拉善盟| 沁水县| 静乐县| 尚志市| 新津县| 科技| 凭祥市| 邹城市| 锦屏县| 新乐市| 嘉善县| 突泉县| 湟中县| 固始县| 科技| 康平县| 红原县| 白城市| 赫章县| 通榆县| 睢宁县| 祥云县| 曲松县| 长乐市| 井研县| 饶平县| 维西| 揭西县| 来凤县|