sweet1cris

Untitled

Sep 7th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.23 KB | None | 0 0
  1.  
  2. void removeDuplicate(String& str){
  3.     if(str.length < 2) {
  4.         return;
  5.     }
  6.     int f = 1, s = 0;
  7.     while(f < str.length) {
  8.         if (str[s] != str[f]) {
  9.             str[++s] = str[f++];
  10.         } else {
  11.             f++;
  12.         }
  13.     }
  14.     str.resize(s + 1);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment