作者JerryChungYC (JerryChung)
標題Re: [閒聊] 每日leetcode
時間2024-11-02 03:26:46
※ 引述《DJYOMIYAHINA (通通打死)》之銘言:
: 其實
: 蠻男的
: 寫了很久
: 我就這樣了
: 一二三四五
這題是easy 所以你要照直覺寫
Python Code:
class Solution:
def makeFancyString(self, s: str) -> str:
for word in set(s):
while word * 3 in s:
s = s.replace(word * 3, word * 2)
return s
--
※ 發信站: 批踢踢實業坊(ptt.org.tw), 來自: 114.45.33.49 (臺灣)
※ 文章網址: https://ptt.org.tw/Marginalman/M.1730489208.A.29B
→ JerryChungYC: 4個a把3個取代會變成3個 所以用while 11/02 03:27