|
|
|
@ -13,7 +13,7 @@ This means that:
|
|
|
|
|
|
|
|
|
|
### Instructions |
|
|
|
|
|
|
|
|
|
You have two numbers represented by a linked list, where each node contains a single digit. |
|
|
|
|
You have two numbers represented by a linked list, where each NodeAddL contains a single digit. |
|
|
|
|
The digits are stored in reverse order, such that the 1’s digit is at the head of the list. |
|
|
|
|
Write a function that adds the two numbers and returns the sum as a linked list |
|
|
|
|
|
|
|
|
@ -22,12 +22,12 @@ Write a function that adds the two numbers and returns the sum as a linked list
|
|
|
|
|
```go |
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
type Node struct { |
|
|
|
|
Next *Node |
|
|
|
|
type NodeAddL struct { |
|
|
|
|
Next *NodeAddL |
|
|
|
|
Num int |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func AddLinkedNumbers(num1, num1 *Node) *Node { |
|
|
|
|
func AddLinkedNumbers(num1, num1 *NodeAddL) *NodeAddL { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
@ -43,19 +43,19 @@ import (
|
|
|
|
|
"fmt" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func pushFront(node *Node, num int) *Node { |
|
|
|
|
func pushFront(node *NodeAddL, num int) *NodeAddL { |
|
|
|
|
// ... |
|
|
|
|
// Write yourself |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
// 3 -> 1 -> 5 |
|
|
|
|
num1 := &Node{Num:5} |
|
|
|
|
num1 := &NodeAddL{Num:5} |
|
|
|
|
num1 = pushFront(num1, 1) |
|
|
|
|
num1 = pushFront(num1, 3) |
|
|
|
|
|
|
|
|
|
// 5 -> 9 -> 2 |
|
|
|
|
num2 := &Node{Num:2} |
|
|
|
|
num2 := &NodeAddL{Num:2} |
|
|
|
|
num2 = pushFront(num2, 9) |
|
|
|
|
num2 = pushFront(num2, 5) |
|
|
|
|
|
|
|
|
|