Created
August 13, 2021 14:39
-
-
Save r14152/379924feb67f63d34a2ece622b4b579d to your computer and use it in GitHub Desktop.
Delete a node from hackerank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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