You are viewing a single comment's thread. Return to all comments →
Here are my c++ approaches of solving this, video explanation here : https://youtu.be/KoDlxS38_ig
Solution 1 : Using loop
int alternatingCharacters(string s) { int result = 0; for(int i = 1; i < s.size(); i++) if(s[i] == s[i-1]) result++; return result; }
Solution 2 : Using regex
int alternatingCharacters(string s) { regex re("A{2,}|B{2,}"); return s.size() - regex_replace(s, re, "*").size(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Alternating Characters
You are viewing a single comment's thread. Return to all comments →
Here are my c++ approaches of solving this, video explanation here : https://youtu.be/KoDlxS38_ig
Solution 1 : Using loop
Solution 2 : Using regex