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

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

LeetCode 2786. Visit Array Positions to Maximize Score

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

You are given a?0-indexed?integer array?nums?and a positive integer?x.

You are?initially?at position?0?in the array and you can visit other positions according to the following rules:

  • If you are currently in position?i, then you can move to?any?position?j?such that?i < j.

  • For each position?i?that you visit, you get a score of?nums[i].

  • If you move from a position?i?to a position?j?and the?parities?of?nums[i]?and?nums[j]?differ, then you lose a score of?x.

Return?the?maximum?total score you can get.

Note?that initially you have?nums[0]?points.

?

Example 1:

Input: nums = [2,3,6,1,9,2], x = 5Output: 13Explanation: We can visit the following positions in the array: 0 -> 2 -> 3 -> 4. The corresponding values are 2, 6, 1 and 9. Since the integers 6 and 1 have different parities, the move 2 -> 3 will make you lose a score of x = 5. The total score will be: 2 + 6 + 1 + 9 - 5 = 13.

Example 2:

Input: nums = [2,4,6,8], x = 3Output: 20Explanation: All the integers in the array have the same parities, so we can visit all of them without losing any score. The total score is: 2 + 4 + 6 + 8 = 20.

?

Constraints:

  • 2 <= nums.length <= 105

  • 1 <= nums[i], x <= 106

--------------------------------------------------


給定一個(gè) 0 索引的整數(shù)數(shù)組 nums 和一個(gè)正整數(shù) x。


您最初位于數(shù)組中的位置 0,您可以根據(jù)以下規(guī)則訪問(wèn)其他位置:


如果您當(dāng)前處于位置 i,那么您可以移動(dòng)到任意位置 j,使得 i < j。

對(duì)于您訪問(wèn)的每個(gè)位置 i,您將獲得 nums[i] 分?jǐn)?shù)。

如果你從位置 i 移動(dòng)到位置 j 并且 nums[i] 和 nums[j] 的奇偶性不同,那么你會(huì)失去 x 的分?jǐn)?shù)。

返回您可以獲得的最高總分。


請(qǐng)注意,最初您有 nums[0] 點(diǎn)。

------------------------------------------

用2個(gè)變量依次去存儲(chǔ)每次到該位置時(shí)候的odd,even的值,最后max返回;


Runtime:?11 ms, faster than?100.00%?of?Java?online submissions for?Visit Array Positions to Maximize Score.

Memory Usage:?55.3 MB, less than?100.00%?of?Java?online submissions for?Visit Array Positions to Maximize Score.


LeetCode 2786. Visit Array Positions to Maximize Score的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
德钦县| 临湘市| 霍州市| 曲阳县| 光山县| 嘉峪关市| 桦甸市| 西平县| 大方县| 曲松县| 丰台区| 锡林浩特市| 南靖县| 汕尾市| 班戈县| 镇巴县| 柞水县| 贺兰县| 平谷区| 裕民县| 丰顺县| 临沧市| 大理市| 纳雍县| 施秉县| 淮滨县| 庆城县| 宜阳县| 通化市| 利川市| 华宁县| 三江| 灵丘县| 宜昌市| 铁岭市| 清徐县| 大港区| 延川县| 彭阳县| 班玛县| 东至县|