leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2696.cpp (504B)
0 class Solution { 1 public: 2 int minLength(string s) const { 3 int n = size(s); 4 while (true) { 5 int j = 0; 6 for (int i = 0; i < n; i++) { 7 if (s[i] == 'A' && s[i + 1] == 'B') 8 i++; 9 else if (s[i] == 'C' && s[i + 1] == 'D') 10 i++; 11 else 12 s[j++] = s[i]; 13 } 14 15 if (j == n) break; 16 s[n = j] = '\0'; 17 } 18 19 return n; 20 } 21 };