A problem in 707. Design Linked List
Shiwei-Luo opened this issue · comments
Shiwei-Luo commented
func (this *MyLinkedList) DeleteAtIndex(index int) {
cur := this
for i := 0; cur != nil; i++ {
if i == index-1 {
break
}
cur = cur.Next
}
if cur != nil && cur.Next != nil {
cur.Next = cur.Next.Next
}
}
It seems that the case that index equals 0 is not taken into account.
halfrost commented
func (this *MyLinkedList) DeleteAtIndex(index int) { cur := this for i := 0; cur != nil; i++ { if i == index-1 { break } cur = cur.Next } if cur != nil && cur.Next != nil { cur.Next = cur.Next.Next } }It seems that the case that index equals 0 is not taken into account.
@Shiwei-Luo You are right. I have fixed this bug. Please pull the latest code.