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

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

Leetcode 2555. Maximize Win From Two Segments

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

There are some prizes on the?X-axis. You are given an integer array?prizePositions?that is?sorted in non-decreasing order, where?prizePositions[i]?is the position of the?ith?prize. There could be different prizes at the same position on the line. You are also given an integer?k.

You are allowed to select two segments with integer endpoints. The length of each segment must be?k. You will collect all prizes whose position falls within at least one of the two selected segments (including the endpoints of the segments). The two selected segments may intersect.

  • For example if?k = 2, you can choose segments?[1, 3]?and?[2, 4], and you will win any prize?i?that satisfies?1 <= prizePositions[i] <= 3?or?2 <= prizePositions[i] <= 4.

Return?the?maximum?number of prizes you can win if you choose the two segments optimally.

?

Example 1:

Input:?prizePositions = [1,1,2,2,3,3,5], k = 2

Output:?7

Explanation:?In this example, you can win all 7 prizes by selecting two segments [1, 3] and [3, 5].

Example 2:

Input:?prizePositions = [1,2,3,4], k = 0

Output:?2

Explanation:?For this example,?one choice?for the segments is?[3, 3]?and?[4, 4],?and you will be able to get?2?prizes.

?

Constraints:

  • 1 <= prizePositions.length <= 105

  • 1 <= prizePositions[i] <= 109

  • 0 <= k <= 109

  • prizePositions?is sorted in non-decreasing order.

  • 這里面其實有個疑問的就是int j=0,在for循環(huán)里面應(yīng)該每次都將j賦值為0啊,,

  • 于是用j=0,放在for循環(huán)中,重新跑了一遍,還是過了,呵呵。。。。


Runtime:?8 ms, faster than?49.54%?of?Java?online submissions for?Maximize Win From Two Segments.

Memory Usage:?53.1 MB, less than?14.31%?of?Java?online submissions for?Maximize Win From Two?Segments.



Leetcode 2555. Maximize Win From Two Segments的評論 (共 條)

分享到微博請遵守國家法律
梧州市| 巴里| 龙泉市| 杭州市| 原阳县| 青冈县| 托克托县| 南川市| 壶关县| 武乡县| 达日县| 莱西市| 铜川市| 阳春市| 丰台区| 修文县| 敦化市| 涡阳县| 龙里县| 福安市| 宽城| 鄯善县| 定日县| 专栏| 乐昌市| 徐州市| 云浮市| 天等县| 游戏| 霍林郭勒市| 唐海县| 玉田县| 和顺县| 云林县| 肇庆市| 桂东县| 弥渡县| 陆丰市| 天台县| 长乐市| 延庆县|