Problems
LinkedList Reverse
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)