I think you need to add additional check if the length of your linked list is 1 (only 1 header) you will have a panic: runtime error: invalid memory address or nil pointer dereference if you try to delete the node that does not exist. Because for previousToDelete.next.data != value will be met with 1 value in the linked list, but the next condition if previousToDelete.next.next == nil will result in error. I just added this condition as well: if l.length == 1 && l.head.data != value { return }
This is great - please keep going!
You teach so well! I managed to implement `remove(value int)` by myself!
keep up the good work :)
I think you need to add additional check if the length of your linked list is 1 (only 1 header) you will have a panic: runtime error: invalid memory address or nil pointer dereference if you try to delete the node that does not exist. Because for previousToDelete.next.data != value will be met with 1 value in the linked list, but the next condition if previousToDelete.next.next == nil will result in error. I just added this condition as well: if l.length == 1 && l.head.data != value {
return
}
Please share via GH repo