www.hackerrank.com/challenges/delete-a-node-from-a-linked-list/problem
package exam.complete;
//https://www.hackerrank.com/challenges/delete-a-node-from-a-linked-list/problem
import exam.SinglyLinkedListNode;
public class DeleteNode {
static SinglyLinkedListNode deleteNode(SinglyLinkedListNode head, int position) {
if(position == 0) return head.next;
SinglyLinkedListNode positionNode = head;
for(int i = 0 ; i < position - 1 ; i++) positionNode = positionNode.next;
positionNode.next = positionNode.next.next;
return head;
}
}
'Programming > Data Structure' 카테고리의 다른 글
[Hackerrank] GetNodeValue (0) | 2020.12.02 |
---|---|
[Hackerrank] FindMergePointofTwoLists (0) | 2020.12.02 |
[Hackerrank] CompareTwoLinkedLists (0) | 2020.12.02 |
[Hackerrank] BalancedBrackets (0) | 2020.12.02 |
[Hackerrank] reverseArray (0) | 2020.12.02 |