Plus One Linked List
The list holds the digits of a non-negative number with the most significant digit first, like 1 -> 2 -> 9 for 129. Add 1 to the number and return the digits of the result in the same format. Watch out for carries, which can add a new digit at the front. The list is passed in as head.
Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.
Example 1
head [1,2,9]
returns [1,3,0]
129 + 1 = 130.
Example 2
head [9,9]
returns [1,0,0]
99 + 1 = 100.
Constraints
1 <= number of nodes <= 200 <= Node.val <= 9- No leading zeros, except the number 0 itself
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.