Leetcode Solution: #206: Reverse Linked List 🐬

leetcode-solution:-#206:-reverse-linked-list-

Question Type: Medium 🎚️
Complexities: Time: O(n), Space: O(n) 🚩

Code: 👇

class Solution {
 public:
  ListNode* reverseList(ListNode* head) {
    if (!head || !head->next)
      return head;

    ListNode* newHead = reverseList(head->next);
    head->next->next = head;
    head->next = nullptr;
    return newHead;
  }
};
Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
6-free-ebooks-to-learn-web-development-

6 Free eBooks to Learn Web Development 📚

Next Post
javascript-template-literals

JavaScript Template Literals

Related Posts