LeetCode Middle of the Linked List Solution Explained - Java

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

in c++ if anyone interested:
ListNode* middleNode(ListNode* head)
{
ListNode* slow = head;
ListNode* fast = head;

while(fast && fast->next)
{
slow = slow->next;
fast = fast->next->next;
}
return slow;
}

Account-ficu
Автор

زلمه محترم وبتختصر لانو اهل الهند طبخو مخي

mosarabea
Автор

Quick and easy explanation 🤯, thank you!

fernandotoledo
Автор

If anyone is interested in recursive version of it:
class Solution {
ListNode* middle;
public:
ListNode* middleNode(ListNode* head) {
middle = head;
return recursion(head);
}

private:
ListNode* recursion(ListNode* head){
if(head && head->next){
middle = middle->next;
return recursion(head->next->next);
}
return middle;
}
};

NeerajSharma-ozmm
Автор

0:14 where are the other leetcode videos? i only see 76 of them from your list.

leej
Автор

i never thought of this in c i am doing dsa in c is it okay

adnanali
Автор

when it has 1-2-3-4-5-6, won't it return 3 instead of 4?

fruitlover
Автор

we don't need the slow pointer here. we can move the head as the slow pointer

dim_
Автор

i've never thought about doing it this way...

scum