You are viewing a single comment's thread. Return to all comments →
Here are my c++ solution, explanation here : https://youtu.be/xf0JsPRH5rs
Solution 1 :
int beautifulBinaryString(string b) { int ans = 0; for(int i = 0; i < b.size();){ string sub = b.substr(i, 3); if(sub == "010") { ans++; i+=3; }else i++; } return ans; }
Solution 2 :
int beautifulBinaryString(string b) { regex re("010"); string c = regex_replace(b, re, ""); return (b.size() - c.size()) / 3; }
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Binary String
You are viewing a single comment's thread. Return to all comments →
Here are my c++ solution, explanation here : https://youtu.be/xf0JsPRH5rs
Solution 1 :
Solution 2 :