mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
20 lines
436 B
C++
20 lines
436 B
C++
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
class Solution {
|
|
public:
|
|
long long minCost(std::string s, std::vector<int> &cost) {
|
|
std::unordered_map<char, long long> m;
|
|
int n = cost.size();
|
|
long long sum = 0, ans = LLONG_MAX;
|
|
for (int i = 0; i < n; i++) {
|
|
m[s[i]] += cost[i];
|
|
sum += cost[i];
|
|
}
|
|
for (auto [k, v] : m) {
|
|
ans = std::min(ans, sum - v);
|
|
}
|
|
return ans;
|
|
}
|
|
}; |