Answers for "how to compare a string with null in c"

1

how compress string in c

#include <bits/stdc++.h>
using namespace std;
class Solution {
   public:
   string solve(string s) {
      string ret = "";
      for(int i = 0; i < s.size(); i++){
         if(ret.size() && ret.back() == s[i]){
            continue;
         }
         ret += s[i];
      }
      return ret;
   }
};
int main(){
   Solution ob;
   cout << (ob.solve("heeeeelllllllloooooo"));
}
Posted by: Guest on January-11-2021

Code answers related to "how to compare a string with null in c"

Browse Popular Code Answers by Language