This commit is contained in:
parent
47d509641b
commit
90da95b8ae
1 changed files with 17 additions and 0 deletions
17
easy/delete_characters_to_make_fancy_string.py
Normal file
17
easy/delete_characters_to_make_fancy_string.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# https://leetcode.com/problems/delete-characters-to-make-fancy-string
|
||||
|
||||
class Solution:
|
||||
def makeFancyString(self, s: str) -> str:
|
||||
l = 0
|
||||
old = None
|
||||
result = []
|
||||
for ch in s:
|
||||
if old == None or old != ch:
|
||||
old = ch
|
||||
l = 1
|
||||
result.append(old)
|
||||
elif old == ch and l <= 2:
|
||||
result.append(old)
|
||||
l += 1
|
||||
return ''.join(result)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue