You are given the head of a singly linked list where each node contains an integer, write a function to calculate the sum of all the values in the list.
An empty list should result in a sum of 0.
1 → 2 → 3 → 4 → null
10
The sum of the nodes is 1 + 2 + 3 + 4 = 10.
None
0
The input list is empty, so the sum is 0.
5 → -7 → null
-2
The sum of the nodes is 5 + (-7) = -2.
1 → 2 → 3 → 4 → null
10