DEV Community

Miss Pooja Anilkumar Patel
Miss Pooja Anilkumar Patel

Posted on

1578. Leetcode solution in CPP

class Solution {
public:
    int minCost(string s, vector<int>& cost) {
        int N = s.size(), ans = 0;
        for (int i = 0; i + 1 < N; ++i) {
            if (s[i] != s[i + 1]) continue;
            if (cost[i] > cost[i + 1]) swap(cost[i], cost[i + 1]);
            ans += cost[i];
        }
        return ans;
    }
};
Enter fullscreen mode Exit fullscreen mode

leetcode

challenge

here is the link for the problem:
https://leetcode.com/problems/minimum-time-to-make-rope-colorful/

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

If you found this post useful, consider leaving a ❤️ or a nice comment!

Got it