This question was asked by Google. Can you solve it? (reverse linked list) #Leetshorts

preview_player
Показать описание
#shorts
Рекомендации по теме
Комментарии
Автор

I just had this yesterday in an exam. I dont even study programming. Google interviews must be harder than this otherwise everybody could get in there

myguy
Автор

I have another approach..by creating three nodes first points to null second points to head third points head.next, then move the train and flip nodes to the opposite direction

_Elfaro
Автор

Yesterday, after implementing singly linked list using malloc in C, I started thinking how can I free the memory.

justcurious
Автор

bro you are talented, i liked your chess game video, make some of that out of the box / no availabe on youtube stuff please
anyone can solve these coding generic questions and youtube is filled with it
make video about how to design architecture of project, how to handle traffic on website in real life

Sksahu_
Автор

Here's the C++ Solution for it

class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode *p = head;
ListNode *q = NULL;
ListNode *r = NULL;

while(p!=NULL){
r = q;
q = p;
p = p->next;
q->next = r;
}
head = q;
return q;
}
};

deepakkumarkhatri
Автор

struct ListNode* reverseList(struct ListNode* head) {
if (head == NULL || head->next == NULL) {
return head;
}

struct ListNode *p = head;
struct ListNode *q = head->next;
struct ListNode *reversed = reverseList(q);
q->next = p;
p->next = NULL;

return reversed;
}

-manikandabharathi.t
Автор

now ! chat GPT is friend for answering leetcode pronbelm!

andreajr
Автор

I have another approach..by creating three nodes first points to null second points to head third points head.next, then move the train and flip nodes to the opposite direction

_Elfaro