Merge branch 'main' of git.bumpsoo.dev:bumpsoo/leetpycode
This commit is contained in:
commit
d74f67ea6b
2 changed files with 45 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