Super Reduced String HackerRank Problem Solution in C++ | Competitive Programming - BeTech India!

Latest

BeTech India! - A place for all your Tech. needs | Solutions of Competitive Programming Problems | Code Explained | Indian Engineering System | Technology News | Current Updates | My Excerpts from Experiences | Coding Tips and much more...

Sunday, May 24, 2020

Super Reduced String HackerRank Problem Solution in C++ | Competitive Programming


#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int len = s.length();
for(int i=0;i<len;)
{
    if(s[i]==s[i+1] && i>-1){
        s.erase(i,2);
        i--; }
    else{
        i++; }
 }
if(!s.empty())
    cout<<s<<"\n";
else
    cout<< "Empty String"<<"\n";
return 0;
}


References:

std::string::erase in C++ 





No comments:

Post a Comment

Guys, if you have any doubts or suggestions please let us know.