BackmediumLinked Lists linked-lists medium

Total Node Weight Calculation Solution

Problem Statement

Given a singly linked list where each node contains an integer weight, implement a function to calculate the total weight of all nodes in the list.

Example 1
Input
[1, 2, 3, 4, 5]
Output
15

Explanation: The total weight is the sum of all node weights, which in this case is 1 + 2 + 3 + 4 + 5 = 15.

Constraints

  • The length of the linked list will be at most 1000 nodes.
  • Each node weight will be an integer between -1000 and 1000.
  • The function will be called with a valid singly linked list.
  • The function should return the total weight as an integer.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free