LeetCode solutions

1302. Delete Characters to Make Fancy String

My accepted Python solution to LeetCode problem 1302, Delete Characters to Make Fancy String, running in 304ms.

  • Difficulty: Easy
  • Python
  • Runtime 304ms
  • Memory 19.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 304ms, memory 19.2MB, accepted 2025-12-31.

python
class Solution:
    def makeFancyString(self, s: str) -> str:
        result = []
        for c in s:
            if len(result) >= 2 and result[-1] == c and result[-2] == c:
                continue
            result.append(c)
        return ''.join(result)

Source