Good Video but the solution is actually O(n ^ 2) time complexity because appending to a string is an O(n) time operation. Consider using a list for res because appending to a list is an O(1) time complexity task. And in the end just return "".join(res)
@MFAWZHAAROONAIML23 күн бұрын
class Solution: def makeFancyString(self, s: str) -> str: result = [] for char in s: if len(result) < 2 or not (result[-1] == char and result[-2] == char): result.append(char) return ''.join(result)