@@ -116,23 +116,23 @@ Take `head = [0, 3, 1, 0, 4, 5, 2, 0]` as an example, let's go through the code
116
116
- ` cur ` points to the second node (value 3).
117
117
- Since ` cur.Val ` is not 0, add ` cur.Val ` to ` sum ` :
118
118
119
- ```
119
+ ``` go
120
120
sum = 0 + 3 = 3
121
121
```
122
122
123
123
### Iteration 2
124
124
- Move ` cur ` to the third node (value 1).
125
125
- Since ` cur.Val ` is not 0, add ` cur.Val ` to ` sum ` :
126
126
127
- ```
127
+ ``` go
128
128
sum = 3 + 1 = 4
129
129
```
130
130
131
131
### Iteration 3
132
132
- Move ` cur ` to the fourth node (value 0).
133
133
- Since ` cur.Val ` is 0, update ` n.Val ` and move ` n ` :
134
134
135
- ```
135
+ ``` go
136
136
n.Val = sum = 4
137
137
n.Next = cur.Next (points to node with value 4 )
138
138
sum = 0
@@ -144,36 +144,37 @@ Take `head = [0, 3, 1, 0, 4, 5, 2, 0]` as an example, let's go through the code
144
144
- Move ` cur ` to the fifth node (value 4).
145
145
- Since ` cur.Val ` is not 0, add ` cur.Val ` to ` sum ` :
146
146
147
- ```
147
+ ``` go
148
148
sum = 0 + 4 = 4
149
149
```
150
150
151
151
### Iteration 5
152
152
- Move ` cur ` to the sixth node (value 5).
153
153
- Since ` cur.Val ` is not 0, add ` cur.Val ` to ` sum ` :
154
154
155
- ```
155
+ ``` go
156
156
sum = 4 + 5 = 9
157
157
```
158
158
159
159
### Iteration 6
160
160
- Move ` cur ` to the seventh node (value 2).
161
161
- Since ` cur.Val ` is not 0, add ` cur.Val ` to ` sum ` :
162
162
163
- ```
163
+ ``` go
164
164
sum = 9 + 2 = 11
165
165
```
166
166
167
167
### Iteration 7
168
168
- Move ` cur ` to the eighth node (value 0).
169
169
- Since ` cur.Val ` is 0, update ` n.Val ` and move ` n ` :
170
170
171
- ```
171
+ ``` go
172
172
n.Val = sum = 11
173
173
n.Next = cur.Next (points to nil , end of the list)
174
174
sum = 0
175
175
n = cur.Next (points to nil )
176
176
```
177
+
177
178
The linked list now looks like this: ` [0, 4, 11] `
178
179
179
180
### End
0 commit comments