nikunjsoni

1047

Jun 28th, 2021
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     string removeDuplicates(string s) {
  4.         int i = 0, n = s.length();
  5.         for (int j = 0; j < n; ++j, ++i) {
  6.             s[i] = s[j];
  7.             if (i > 0 && s[i - 1] == s[i]) // count = 2
  8.                 i -= 2;
  9.         }
  10.         return s.substr(0, i);
  11.     }
  12. };
RAW Paste Data