Тёмный

Remove Nodes From Linked List - LeetCode 2487 - Python Solution Code Answer and Explanation 

AlgoSkills
Подписаться 42
Просмотров 2,6 тыс.
50% 1

MASTER data structures and algorithms with this course - bit.ly/algoskillsyt
In this video I am going to be walking through how to solve LeetCode 2487. My solution will be a recursive function created in Python, with a full visual explanation and question breakdown.

Хобби

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

 

1 дек 2022

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 6   
@aynuayex
@aynuayex 6 месяцев назад
here is iteratively class Solution: def removeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]: # reverse the list pre, cur = None, head while cur: temp = cur.next cur.next = pre pre = cur cur = temp # remove the node that is less than the max(greater value to the right) head = pre cur = pre.next max = pre.val while cur: if cur.val < max: pre.next = cur.next cur.next = None cur = pre.next else: max = cur.val pre = cur cur = cur.next # reverse the list again pre, cur = None, head while cur: temp = cur.next cur.next = pre pre = cur cur = temp return pre
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with this course - bit.ly/algoskillsyt
@fortznite8150
@fortznite8150 Год назад
Interesting but can you do it iteratively?
@algoskills
@algoskills Год назад
I have not attempted but it should be possible to do it iteratively too
@motivationkiaag1601
@motivationkiaag1601 Год назад
For iteratively You have to first reverse the list . Then traverse it from end ( it means from new head ) then take a Max value and check if a number is greater then current value the update max and if you get smaller value then you have to make connection between current node to those node which have greater value then finally reverse again the list and return head of list . I hope it helps you .
@sujaydas5024
@sujaydas5024 8 месяцев назад
public class Solution { public ListNode RemoveNodes(ListNode head) { ListNode current = head; ListNode l = current; ListNode r = current.next; ListNode prev = null; ListNode dummy = new ListNode(0); dummy.next = current; while(current != null) { while(l != null && r != null) { if(l.val
Далее
Remove K Digits - Leetcode 402 - Python
14:36
Просмотров 58 тыс.
Would you help?!😳
00:32
Просмотров 3,5 млн
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Palindrome Linked List - Leetcode 234 - Python
11:06
Просмотров 89 тыс.
4 июля 2024 г.
0:20
Просмотров 2,5 млн
Who has won ?? 😀 #shortvideo #lizzyisaeva
0:24
Просмотров 16 млн