mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
251103
This commit is contained in:
30
25/11/1578.cpp
Normal file
30
25/11/1578.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
int minCost(std::string colors, std::vector<int> &neededTime)
|
||||
{
|
||||
int n = colors.size();
|
||||
colors += '#';
|
||||
int m = 0, count = 0, ans = 0;
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
m = std::max(neededTime[i], m);
|
||||
count += neededTime[i];
|
||||
if (colors[i] == colors[i + 1])
|
||||
{
|
||||
continue;
|
||||
};
|
||||
ans += count - m;
|
||||
m = 0;
|
||||
count = 0;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string c = "abaac";
|
||||
std::vector<int> need = {1, 2, 3, 4, 5};
|
||||
std::cout<<minCost(c, need);
|
||||
}
|
||||
Reference in New Issue
Block a user