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.
Input: head = [1,8,9]
Output: [3,7,8]
Explanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.
Input: head = [9,9,9]
Output: [1,9,9,8]
Explanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998.
[1, 10^4]
0 <= Node.val <= 9
先做一次 reverse 將鍊結串列翻轉過來,會達成從低位數到高位數的排列,我們用此順序做乘法,並使用一個 carry 紀錄進位,若是最後一個節點尚有 carry,則新增一個節點。