Untitled
unknown
c_cpp
10 months ago
635 B
4
Indexable
class Solution {
public:
int secondsToRemoveOccurrences(string s) {
string newStr= s;
int strSize= s.size();
bool processed= false;
int seconds=0;
while(!processed){
bool found01= false;
for(int i=1;i<strSize;i++){
if(s[i]=='1' && s[i-1]=='0'){
newStr[i]= '0';
newStr[i-1]= '1';
found01= true;
}
}
if(!found01) processed= true;
else seconds++;
s= newStr;
}
return seconds;
}
};Editor is loading...
Leave a Comment