e-olymp
favorite We need a little bit of your help to keep things running, click on this banner to learn more
Competitions

class LinkedList

LinkedList Reverse

Reverse a linked list.

Definition of a single linked list:

// Java
class ListNode {
  int val;
  ListNode next;
  ListNode(int x) {
    val = x;
    next = null;
  }
}
// C++
class ListNode
{
public:
  int val;
  ListNode *next;
  ListNode(int x) : val(x), next(NULL) {}
};

Implement function reverse to reverse a linked list.

// Java
ListNode reverse(ListNode head)
// C++
ListNode* reverse(ListNode *head)

Example

prb10046.gif

Time limit 1 second
Memory limit 128 MiB
Author Mykhailo Medvediev