Re: [閒聊] 每日leetcode
看板Marginalman作者DJYOSHITAKA (franchouchouISBEST)時間1年前 (2024/05/30 00:41)推噓2(2推 0噓 3→)留言5則, 4人參與討論串293/1554 (看更多)
我也不知道我在寫什麼
明明簡單記進位就好了
def numSteps(self, s: str) -> int:
cnt = 0
i = len(s)-1
while s[i] == '0':
cnt += 1
i -= 1
last = i
for j in range(i, -1, -1):
if s[j] == '0':
cnt += (last-j+1)
last = j
if last != 0:
cnt += (last+2)
return cnt
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.79.34.96 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1717000910.A.71D.html
推
05/30 00:44,
1年前
, 1F
05/30 00:44, 1F
推
05/30 00:46,
1年前
, 2F
05/30 00:46, 2F
→
05/30 00:58,
1年前
, 3F
05/30 00:58, 3F
→
05/30 01:02,
1年前
, 4F
05/30 01:02, 4F
→
05/30 01:02,
1年前
, 5F
05/30 01:02, 5F
討論串 (同標題文章)
完整討論串 (本文為第 293 之 1554 篇):