Re: [閒聊] 每日leetcode
看板Marginalman作者DJYOMIYAHINA (通通打死)時間11月前 (2025/01/05 20:09)推噓0(0推 0噓 2→)留言2則, 2人參與討論串1246/1554 (看更多)
最近真的超懶刷
整個腦子變的鈍鈍的==
一二三四五
def shiftingLetters(self, s: str, shifts: List[List[int]]) -> str:
tmp = [0 for _ in range(len(s))]
for shft in shifts:
if shft[2]==1:
tmp[shft[0]] += 1
if shft[1]+1 < len(s):
tmp[shft[1]+1] -= 1
else:
tmp[shft[0]] -= 1
if shft[1]+1 < len(s):
tmp[shft[1]+1] += 1
ans = ""
cur_shft = 0
for i in range(len(s)):
cur_shft += tmp[i]
ans += chr(((ord(s[i])-ord('a')+cur_shft) % 26) + ord('a'))
return ans
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736078947.A.0A6.html
→
01/05 20:18,
11月前
, 1F
01/05 20:18, 1F
→
01/05 20:30,
11月前
, 2F
01/05 20:30, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1246 之 1554 篇):