diff --git a/Reverse Linked List.cpp b/Reverse Linked List.cpp new file mode 100644 index 0000000..d1b0791 --- /dev/null +++ b/Reverse Linked List.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + ListNode* reverseList(ListNode* head) { + ListNode *cur = head; + ListNode *next = NULL; + ListNode *prev = NULL; + + while (cur != NULL){ + next = cur->next; + cur->next = prev; + prev = cur; + cur= next; + + } + head = prev; + return head; + } +};