Leetcode-5064 Remove All Adjacent Duplicates In String(删除字符串中的所有相邻重复项)

 1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 2 
 3 class Solution
 4 {
 5     public:
 6         string removeDuplicates(string S)
 7         {
 8                 _for(i,0,S.size()-1)
 9                 {
10                     if(S[i]==S[i+1])
11                     {
12                         S.erase(i,2);
13                         i -= 2;
14                         if(i==-2)
15                             i = -1;
16                     }
17                     if(S.size()<=1)
18                         break;
19                 }
20             return S;
21         }
22 };
原文地址:https://www.cnblogs.com/Asurudo/p/10888748.html