作者DJYOMIYAHINA (通通打死)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Thu Jul 4 08:11:39 2024
好久沒有遇到linked list了
有過就好
對ㄚ==
一二三四五
def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:
def help(head, cur_sum):
if head is None:
return None
elif head.val == 0:
n = ListNode(cur_sum)
n.next = help(head.next, 0)
return n
else:
return help(head.next, cur_sum+head.val)
return help(head,0).next
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1720051901.A.668.html
※ 編輯: DJYOMIYAHINA (125.229.37.69 臺灣), 07/04/2024 08:11:57
推 sustainer123: 大師 07/04 08:18
推 rainkaras: 大師 07/04 08:37
推 smart0eddie: 大師 07/04 13:55