#1544

Make The String Great

pupil · 300 · lc easy +20 · verified · 68.4% accepted · 3,219 likes · top 75%

Description

A mixed-case string s is "good" if it contains no adjacent pair of the same letter in different cases (e.g. 'a' next to 'A'). Repeatedly remove any such adjacent bad pair until no more exist. Return the resulting good string (guaranteed unique; an empty string is also good).

Example 1:

Input: s = "leEeetcode"
Output: "leetcode"
Explanation: In the first step, either you choose i = 1 or i = 2, both will result "leEeetcode" to be reduced to "leetcode".

Example 2:

Input: s = "abBAcC"
Output: ""
Explanation: We have many possible scenarios, and all lead to the same answer. For example:
"abBAcC" --> "aAcC" --> "cC" --> ""
"abBAcC" --> "abBA" --> "aA" --> ""

Example 3:

Input: s = "s"
Output: "s"

Code

1
2
3