Search

2024-03-12 Leetcode Daily Problem

생성일
2024/03/12 13:22
태그
알고리즘
날짜
2024/03/12
3 more properties
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def removeZeroSumSublists(self, head: Optional[ListNode]) -> Optional[ListNode]: runner = dummy = ListNode(next=head) acc = 0 acc_to_node = dict() while runner: acc += runner.val acc_to_node[acc] = runner runner = runner.next acc, runner = 0, dummy while runner: acc += runner.val runner.next = acc_to_node[acc].next runner = runner.next return dummy.next
Python
복사