Class Solution
java.lang.Object
g1501_1600.s1578_minimum_time_to_make_rope_colorful.Solution
1578 - Minimum Time to Make Rope Colorful.<p>Medium</p>
<p>Alice has <code>n</code> balloons arranged on a rope. You are given a <strong>0-indexed</strong> string <code>colors</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> balloon.</p>
<p>Alice wants the rope to be <strong>colorful</strong>. She does not want <strong>two consecutive balloons</strong> to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it <strong>colorful</strong>. You are given a <strong>0-indexed</strong> integer array <code>neededTime</code> where <code>neededTime[i]</code> is the time (in seconds) that Bob needs to remove the <code>i<sup>th</sup></code> balloon from the rope.</p>
<p>Return <em>the <strong>minimum time</strong> Bob needs to make the rope <strong>colorful</strong></em>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/12/13/ballon1.jpg" alt="" /></p>
<p><strong>Input:</strong> colors = “abaac”, neededTime = [1,2,3,4,5]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> In the above image, ‘a’ is blue, ‘b’ is red, and ‘c’ is green.</p>
<p>Bob can remove the blue balloon at index 2. This takes 3 seconds.</p>
<p>There are no longer two consecutive balloons of the same color. Total time = 3.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/12/13/balloon2.jpg" alt="" /></p>
<p><strong>Input:</strong> colors = “abc”, neededTime = [1,2,3]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> The rope is already colorful. Bob does not need to remove any balloons from the rope.</p>
<p><strong>Example 3:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/12/13/balloon3.jpg" alt="" /></p>
<p><strong>Input:</strong> colors = “aabaa”, neededTime = [1,2,3,4,1]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> Bob will remove the ballons at indices 0 and 4. Each ballon takes 1 second to remove.</p>
<p>There are no longer two consecutive balloons of the same color. Total time = 1 + 1 = 2.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == colors.length == neededTime.length</code></li>
<li><code>1 <= n <= 10<sup>5</sup></code></li>
<li><code>1 <= neededTime[i] <= 10<sup>4</sup></code></li>
<li><code>colors</code> contains only lowercase English letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minCost
-