Skip to content

Latest commit

 

History

History

templates

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Template

Header Signatures

/**
 * Author: 1chooo<hugo970217@gmail.com>
 * Problem: 
 * Runtime: ms (%)
 */

const static auto _ = []() {
    cin.tie(nullptr)->sync_with_stdio(false);
    return nullptr;
}();
"""
* Author: 1chooo<hugo970217@gmail.com>
* Problem: 
* Runtime: ms (%)
"""
/**
 * Author: 1chooo<hugo970217@gmail.com>
 * Problem: 
 * Runtime: ms (%)
 */

Intuition

Approach

Complexity

  • Time complexity:
  • Space complexity:

Code

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */

func mergeNodes(head *ListNode) *ListNode {
	var sum int = 0
	var n *ListNode = head.Next

	for cur := head.Next; cur != nil; cur = cur.Next {
		if cur.Val == 0 {
			n.Val = sum
			sum = 0
			n.Next = cur.Next
			n = cur.Next
		} else {
			sum += cur.Val
		}
	}

	return head.Next
}