aboutsummaryrefslogtreecommitdiff
path: root/make_string_great.cpp
blob: 190bbed0fcc02a9b7cf206bbf07100a2e5be0609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "leetcode.h"

class Solution {
public:
  string makeGood(string s) {
    int n = s.size();
    if (n < 2)
      return s;
    while (n > 1) {
      bool pair = false;
      for (int i = 0; i < n; i++) {
        char curr = s[i], next = s[i + 1];
        if (abs(curr - next) == 32) {
          s = s.substr(0, i) + s.substr(i + 2);
          pair = true;
          break;
        }
      }
      if (!pair)
        break;
    }
    return s;
  }
};

int main() {
  Solution obj;
  cout << obj.makeGood("HhvmLxpqQPXlMVQWwq");
}