Posted on

Description

Submission

class Solution {
public:
    int minFlips(string target) {
        int cnt = 0;
        
        int n = target.size();
        
        for(int i = 0; i < n - 1; ++i) {
            if(target[i] == '1' && target[i+1] == '0') cnt++;
        }
        cnt *= 2;
        if(target.back() == '1') cnt++;
        return cnt;
    }
};

// 001011101
    
// 000000000
// 001111111
// 001000000
// 001011111
// 001011100
// 001011101
    
    
// 10100

// 00000
// 11111
// 10000
// 10111
// 10100

Leave a Reply

Your email address will not be published. Required fields are marked *