Description
Submission
class Solution { public: int minCost(string s, vector<int>& cost) { int ret = 0; for(int i = 0; i < s.length();) { int maxVal = 0; int sum = 0; int j = i; for(; j < s.length() && s[i] == s[j]; ++j) { sum += cost[j]; maxVal = max(maxVal, cost[j]); } ret += sum - maxVal; i = j; } return ret; } };