Skip to content

Instantly share code, notes, and snippets.

@r14152
Created August 13, 2021 14:39
Show Gist options
  • Save r14152/379924feb67f63d34a2ece622b4b579d to your computer and use it in GitHub Desktop.
Save r14152/379924feb67f63d34a2ece622b4b579d to your computer and use it in GitHub Desktop.
Delete a node from hackerank
func deleteNode(llist *SinglyLinkedListNode, position int32) *SinglyLinkedListNode {
// Write your code here
var count int32
head := llist
if head == nil {
return llist
}
if position == 0{
return llist.next
}
for head.next != nil {
if count+1 == position {
temp := head.next
head.next = temp.next
temp = nil
break
}
count++
head = head.next
}
return llist
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment