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

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

leetcode 1578. Minimum Time to Make Rope Colorful

2022-03-26 10:25 作者:您是打尖兒還是住店呢  | 我要投稿


Medium

93838Add to ListShare

Alice has?n?balloons arranged on a rope. You are given a?0-indexed?string?colors?where?colors[i]?is the color of the?ith?balloon.

Alice wants the rope to be?colorful. She does not want?two consecutive balloons?to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it?colorful. You are given a?0-indexed?integer array?neededTime?where?neededTime[i]?is the time (in seconds) that Bob needs to remove the?ith?balloon from the rope.

Return?the?minimum time?Bob needs to make the rope?colorful.

?

Example 1:

Input: colors = "abaac", neededTime = [1,2,3,4,5]Output: 3Explanation: In the above image, 'a' is blue, 'b' is red, and 'c' is green. Bob can remove the blue balloon at index 2. This takes 3 seconds. There are no longer two consecutive balloons of the same color. Total time = 3.

Example 2:

Input: colors = "abc", neededTime = [1,2,3]Output: 0Explanation: The rope is already colorful. Bob does not need to remove any balloons from the rope.

Example 3:

Input: colors = "aabaa", neededTime = [1,2,3,4,1]Output: 2Explanation: Bob will remove the ballons at indices 0 and 4. Each ballon takes 1 second to remove. There are no longer two consecutive balloons of the same color. Total time = 1 + 1 = 2.

?

Constraints:

  • n == colors.length == neededTime.length

  • 1 <= n <= 105

  • 1 <= neededTime[i] <= 104

  • colors?contains only lowercase English letters.

Runtime:?5 ms, faster than?98.81%?of?Java?online submissions for?Minimum Time to Make Rope Colorful.

Memory Usage:?51.1 MB, less than?89.11%?of?Java?online submissions for?Minimum Time to Make Rope Colorful.

用一個變量,來存儲第一個數(shù)據(jù),以后依次跟后面的進行比對,相同的時候,ans加一下2個的最小值,然后讓后面的值等于較大的值,為啥等于較大的值,主要是題解是要最小值,那就要較大值去做比較更好些;以此類推就行的。

leetcode 1578. Minimum Time to Make Rope Colorful的評論 (共 條)

分享到微博請遵守國家法律
吉首市| 淮北市| 托克托县| 庆阳市| 柏乡县| 密山市| 潢川县| 孟州市| 重庆市| 越西县| 龙陵县| 涪陵区| 桐梓县| 灌阳县| 永平县| 吉林省| 汉寿县| 安康市| 新龙县| 金平| 威信县| 中卫市| 昭通市| 大连市| 博湖县| 沙坪坝区| 山阳县| 桑植县| 霍林郭勒市| 威远县| 浏阳市| 昔阳县| 雅安市| 南通市| 泰州市| 玉屏| 永平县| 彰化市| 修武县| 罗山县| 枝江市|