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

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

LeetCode 2302. Count Subarrays With Score Less Than K

2023-04-14 15:00 作者:您是打尖兒還是住店呢  | 我要投稿

The?score?of an array is defined as the?product?of its sum and its length.

  • For example, the score of?[1, 2, 3, 4, 5]?is?(1 + 2 + 3 + 4 + 5) * 5 = 75.

Given a positive integer array?nums?and an integer?k, return?the?number of non-empty subarrays?of?nums?whose score is?strictly less?than?k.

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

?

Example 1:

Input: nums = [2,1,4,3,5], k = 10

Output: 6

Explanation:

The 6 subarrays having scores less than 10 are:?

- [2] with score 2 * 1 = 2.

- [1] with score 1 * 1 = 1.?

- [4] with score 4 * 1 = 4.?

- [3] with score 3 * 1 = 3.

- [5] with score 5 * 1 = 5.?

- [2,1] with score (2 + 1) * 2 = 6.?

Note that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10 and 36 respectively, while we need scores strictly less than 10.

Example 2:

Input: nums = [1,1,1], k = 5

Output: 5

Explanation:

Every subarray except [1,1,1] has a score less than 5.

[1,1,1] has a score (1 + 1 + 1) * 3 = 9,

which is greater than 5.?

Thus, there are 5 subarrays having scores less than 5.

?先放一個(gè)超時(shí)的代碼,

數(shù)據(jù)都沒問題,但是就是超時(shí)了。

然后就是這個(gè)雙指針的方法,就是能過,我挺奇怪的。。。時(shí)間復(fù)雜度應(yīng)該是一樣的啊。


Constraints:

  • 1 <= nums.length <= 105

  • 1 <= nums[i] <= 105

  • 1 <= k <= 1015


Runtime:?5 ms, faster than?14.17%?of?Java?online submissions for?Count Subarrays With Score Less Than K.

Memory Usage:?52.7 MB, less than?56.25%?of?Java?online submissions for?Count Subarrays With Score Less Than K.


LeetCode 2302. Count Subarrays With Score Less Than K的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
米脂县| 宁陕县| 葵青区| 英超| 富锦市| 盐亭县| 苏尼特左旗| 彰化市| 黎城县| 平潭县| 金平| 沙坪坝区| 宜阳县| 六安市| 澎湖县| 武安市| 新绛县| 岗巴县| 禄劝| 巴东县| 海淀区| 曲靖市| 巴里| 英吉沙县| 隆德县| 海城市| 广昌县| 东源县| 自贡市| 珠海市| 炉霍县| 遂溪县| 浦县| 白朗县| 辽阳市| 杨浦区| 房产| 民乐县| 中西区| 康马县| 罗江县|