1. 给你一个字符串 s 和一个整数数组 cost ,其中 cost[i] 是从 s 中删除字符 i 的代价。
    2. 返回使字符串任意相邻两个字母不相同的最小删除成本。
    3. 请注意,删除一个字符后,删除其他字符的成本不会改变。
    4. 示例 1
    5. 输入:s = "abaac", cost = [1,2,3,4,5]
    6. 输出:3
    7. 解释:删除字母 "a" 的成本为 3,然后得到 "abac"(字符串中相邻两个字母不相同)。
    8. 示例 2
    9. 输入:s = "abc", cost = [1,2,3]
    10. 输出:0
    11. 解释:无需删除任何字母,因为字符串中不存在相邻两个字母相同的情况。
    12. 示例 3
    13. 输入:s = "aabaa", cost = [1,2,3,4,1]
    14. 输出:2
    15. 解释:删除第一个和最后一个字母,得到字符串 ("aba")
    16. 提示:
    17. s.length == cost.length
    18. 1 <= s.length, cost.length <= 10^5
    19. 1 <= cost[i] <= 10^4
    20. s 中只含有小写英文字母
    21. 来源:力扣(LeetCode
    22. 链接:https://leetcode-cn.com/problems/minimum-deletion-cost-to-avoid-repeating-letters
    23. 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

    我的解

    1. class Solution {
    2. public int minCost(String s, int[] cost) {
    3. char[] cs = s.toCharArray();
    4. int price = 0;
    5. int index = 0;
    6. for(int i = 1; i < s.length(); i++){
    7. if(cs[index] == cs[i]){
    8. price += Math.min(cost[index], cost[i]);
    9. index = cost[index] > cost[i] ? index : i;
    10. }else{
    11. index = i;
    12. }
    13. }
    14. return price;
    15. }
    16. }