Problem
https://www.hackerrank.com/challenges/reverse-a-doubly-linked-list/problem
Think
- LinkedList의 Reserve를 직접 구현하는 문제이다.
Solved Code
// Complete the reverse function below.
static DoublyLinkedListNode reverse(DoublyLinkedListNode head) {
DoublyLinkedListNode prevNode = null;
DoublyLinkedListNode curNode = head;
DoublyLinkedListNode nextNode = head.next;
curNode.next = prevNode;
while(nextNode != null) {
prevNode = curNode;
curNode = nextNode;
nextNode = curNode.next;
curNode.next = prevNode;
}
return curNode;
}