Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
395 B
0
Indexable
Never
#define ll long long
class Solution {
public:
    long long minimumSteps(string s) {
        ll n=s.length();
        ll j=n-1;
        while(s[j]=='1' && j>0) j--;
        ll res=0;

        for(ll i=j-1;i>=0;i--){
            if(s[i]=='1') {
                res+=j-i;
                s[i]='0';
                s[j]='1';
                j--;
            }
        }
        return res;
    }
};
Leave a Comment