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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 304ms, memory 19.2MB, accepted 2025-12-31.
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)