Leetcode 1302 Solution

This article provides solution to leetcode question 1302 (delete-characters-to-make-fancy-string)

https://leetcode.com/problems/delete-characters-to-make-fancy-string

Solution

class Solution:
    def makeFancyString(self, s: str) -> str:
        i = 0
        ans = ""
        while i < len(s):
            j = i

            while j < len(s) - 1 and s[i] == s[j + 1]:
                j += 1

            ans += min((j - i + 1), 2) * s[i]
            i = j + 1

        return ans