# Leetcode: Plus One Linked List

Similar Problems:

Given a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer.

You may assume the integer do not contain any leading zero, except the number 0 itself.

The digits are stored such that the most significant digit is at the head of the list.

Example:

```Input:
1->2->3

Output:
1->2->4
```

Github: code.dennyzhang.com

Credits To: leetcode.com

Leave me comments, if you have better ways to solve.

```## Blog link: https://code.dennyzhang.com/plus-one-linked-list
## Basic Ideas: Reverse the link. Add 1 with possible carry. Then reverse it back
##
## Complexity:
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
"""
:rtype: ListNode
"""

while has_carry:
p.val += 1
if p.val >= 10:
p.val = p.val % 10
has_carry = True
else:
has_carry = False
# add one more node, if required
if has_carry and p.next is None:
p.next = ListNode(0)
p = p.next

if head is None: return None