#1957

Delete Characters to Make Fancy String

newbie · 240 · lc easy +18 · premium · verified · 74.1% accepted · 1,177 likes · top 84%

Description

A fancy string never has three or more consecutive identical characters.

Given a string s, delete the minimum number of characters to make it fancy, then return the result. The answer is guaranteed to be unique.

Example 1:

Input: s = "leeetcode"
Output: "leetcode"
Explanation:
Remove an 'e' from the first group of 'e's to create "leetcode".
No three consecutive characters are equal, so return "leetcode".

Example 2:

Input: s = "aaabaaaa"
Output: "aabaa"
Explanation:
Remove an 'a' from the first group of 'a's to create "aabaaaa".
Remove two 'a's from the second group of 'a's to create "aabaa".
No three consecutive characters are equal, so return "aabaa".

Example 3:

Input: s = "aab"
Output: "aab"
Explanation: No three consecutive characters are equal, so return "aab".

Code

1
2
3