Solved! Leetcode 2816. Double a Number Represented as a Linked List

Description: Double a Number Represented as a Linked List

You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.

Return the head of the linked list after doubling it.

Example 1

Example 2

Constraints

  • The number of nodes in the list is in the range [1, 104]
  • 0 <= Node.val <= 9
  • The input is generated such that the list represents a number that does not have leading zeros, except the number 0 itself.

Solution

Time Complexity

O(n), where n is the number of nodes in a linked list

Space Complexity

O(1)

Rate this post

Leave a Reply