Source Code: class Solution: def makeFancyString(self, s: str) -> str: ''' To solve this problem, we basically have to identify the part of the string where there are at least 3 consecutive characters. To idenfity this, we can go through each character in the string, and check if the current character is equal to the two characters right before it. If it is, we don't add that character in our character building string. If it isn't , we continue adding it on to our result final string :D ''' res = "" for i in range(len(s)): if i > 1 and s[i] == s[i-1] == s[i-2]: continue else: res += s[i] return res
Source Code:
class Solution:
def makeFancyString(self, s: str) -> str:
'''
To solve this problem, we basically have to identify
the part of the string where there are at least 3 consecutive
characters. To idenfity this, we can go through each character
in the string, and check if the current character is equal
to the two characters right before it. If it is, we don't
add that character in our character building string. If it
isn't , we continue adding it on to our result final string :D
'''
res = ""
for i in range(len(s)):
if i > 1 and s[i] == s[i-1] == s[i-2]:
continue
else:
res += s[i]
return res