Pregunta de entrevista de Apple

Reverse a singly linked list

Respuesta de la entrevista

Anónimo

6 jun 2026

class Solution { public: ListNode* reverseList(ListNode* head) { if (head == nullptr || head->next == nullptr) return head; ListNode* newHead = reverseList(head->next); head->next->next = head; head->next = nullptr; return newHead; } };