Тёмный
No video :(

Middle of the Linked List - Leetcode 876 - Python 

NeetCodeIO
Подписаться 166 тыс.
Просмотров 23 тыс.
50% 1

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🥷 Discord: / discord
🐦 Twitter: / neetcode1
🐮 Support the channel: / neetcode
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
Problem Link: leetcode.com/p...
0:00 - Read the problem
0:30 - Drawing Explanation
3:55 - Coding Explanation
leetcode 876
#neetcode #leetcode #python

Опубликовано:

 

14 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 23   
@kalvpsia8120
@kalvpsia8120 5 месяцев назад
i did a similar question. it was leetcode 2095, "delete the middle node of a linked list" from leetcode 75. initially, i counted the nodes and from there, i found out where the middle node was by taking the count / 2 and then went through the linked list again to delete the middle node. i then tried the slow and fast pointer approach, but to my surprise, it resulted in near identical runtimes (2 ms difference) and memory usage. i assumed the slow and fast pointer approach would be faster since we only pass through the linked list once. edit: i realized after rewatching the video that we technically pass through the linked list twice. so, it makes sense why it resulted in identical results.
@priyavardhanpatel6155
@priyavardhanpatel6155 Год назад
awesome thank you so much for all of your clean and simple code solution explanation.
@PJSCode69
@PJSCode69 23 дня назад
I was always wondering why they use fast and fast.next, I traced it saw the solution and was still confused, thankyou for this.
@Alankrit96
@Alankrit96 7 месяцев назад
Thanks! In case any of you are wondering what to do if the definition of Middle Element changes for a linked list with even number of elements, i.e. if in the linked list with values [1,2,3,4,5,6], the middle element is 3 and not 4 as given in the problem, here's the solution with two pointer method: public class Solution { public ListNode MiddleNode(ListNode head) { ListNode fast = head; ListNode slow = head; while(fast.next!=null && fast.next.next!=null){ slow = slow.next; fast = fast.next.next; } return slow; } }
@JK-de2gh
@JK-de2gh Месяц назад
definetly a neet code!!
@GermansLikeBeer
@GermansLikeBeer 6 месяцев назад
Thanks for the video explanation, and I understand conceptually why it works and how to implement it in code (typescript in my case). Where I'm lost is the given input and output values. Can you please explain why in the question it gives the input and output as an array of numbers even though the class is ListNode, which is clearly defined as not simply an array of numbers? I really don't understand.
@tomonkysinatree
@tomonkysinatree Месяц назад
It's just a representation of a linked list, you can quickly see the expected value and the order of their nodes in that representation.
@squid84202
@squid84202 8 месяцев назад
It's funny working through Grind 75, I think we used a similar approach to account for cycles in a linkedlist and where to break out of it, I think it was 141
@akash5653
@akash5653 Год назад
Thanks. Keep uploading videos!
@mirshodoripov1035
@mirshodoripov1035 Год назад
Hi Neetcode, Thank you for a great solution. is it your next channel?
@ranjithragul
@ranjithragul Год назад
Hi Neetcode, can we get weekly contest solution video.
@srinivassr5067
@srinivassr5067 2 месяца назад
I solved it similarly in java and I got a NullPointerExpection because fast.next.next is not defined. What if the fast.next is the last node? So I solved by splitting that line into two parts, this is the whole logic I wrote: while(fast != null && fast.next != null){ fast = fast.next; if(fast == null) break; if(fast.next != null) fast = fast.next; slow = slow.next; }
@eshw23
@eshw23 Год назад
God
@rafinha0206
@rafinha0206 7 месяцев назад
eu acho que seria O(N/2)
@kalvpsia8120
@kalvpsia8120 5 месяцев назад
i can see why you may think that, but we don't necessarily measure the actual time an algorithm takes. so O(n/2) reduces to O(n) because we remove all constants.
@rose9466
@rose9466 Год назад
Can you explain also worst and best case scenario , and big O notation
@infiniteloop5449
@infiniteloop5449 Год назад
He explains it in the video....
@hookmem
@hookmem Год назад
i cant understand why we wrote while fast and fast.next: What does it mean? While fast and fast.next != what? !=0 or !=True? how we can rewrite it to understand better
@ameydhote9170
@ameydhote9170 Год назад
It’s written to check whether they are NONE or not, cos if it’s none then we are at the end of the linked list and the loop is terminated
@devinpadron5
@devinpadron5 9 месяцев назад
Writing "while fast" is the same as writing "while fast == True". If "fast" is pointing to a node its considered True.
@Kokurorokuko
@Kokurorokuko 5 месяцев назад
it's Python's way of saying fast.next is not None
@petyap7600
@petyap7600 10 месяцев назад
Stop. It's not a real neetcode. What the f?
Далее
Add to Array-Form of Integer - Leetcode 989 - Python
12:35
How I would learn Leetcode if I could start over
18:03
Просмотров 429 тыс.
Мухочирон эхтиёт бошед!
01:31
Просмотров 98 тыс.
NOOOO 😂😂😂
00:14
Просмотров 10 млн
Хитрость старого мастера #diy
00:54
Reverse Linked List II - Leetcode 92 - Python
16:03
Просмотров 76 тыс.
Palindrome Linked List - Leetcode 234 - Python
11:06
Просмотров 92 тыс.
5 Useful F-String Tricks In Python
10:02
Просмотров 293 тыс.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Leetcode - Odd Even Linked List (Python)
7:15
Просмотров 6 тыс.
Lemonade Change - Leetcode 860 - Python
10:37
Просмотров 1,7 тыс.