Back to Browse

LeetCode 21: Merge Two Sorted Lists ITERATIVELY - Interview Prep Ep 61

4.6K views
Feb 11, 2020
11:50

⭐ Shop on Amazon to support me: https://www.amazon.com/?tag=fishercoder0f-20 ⭐ NordVPN to protect your online privacy: https://go.nordvpn.net/aff_c?offer_id=15&aff_id=82405&url_id=902 ⭐ NordPass to help manage all of your passwords: https://go.nordpass.io/aff_c?offer_id=488&aff_id=82405&url_id=9356 Here's the RECURSIVE version: https://youtu.be/bdWOmYL5d1g ⭐ Support my channel and connect with me: https://www.youtube.com/channel/UCPL5uAbYQ40HwAdOe4ikI0w/join LeetCode 21. Merge Two Sorted Lists Problem link: https://leetcode.com/problems/merge-two-sorted-lists/ Solutions explained (Iterative approach): 1. We'll initialize two nodes: prev and curr. Prev is the one used to return final result, curr is the one to help us merge the smaller node from the two lists; 2. Then we'll have a while loop to compare the two nodes: we'll merge the smaller one to curr.next, and then move the smaller node and curr towards the right until either one of the two lists becomes null; 3. When either one becomes null, we'll just assign the other non-null one to curr.next and return prev.next; Time: O(m + n) Space: O(1) // TOOLS THAT I USE: ○ Memory Foam Set Keyboard Wrist Rest Pad - https://amzn.to/3cOGOAj ○ Electric Height Adjustable Standing Desk - https://amzn.to/2S9YexJ ○ Apple Magic Keyboard (Wireless, Rechargable) - https://amzn.to/36gy5FJ ○ Apple Magic Trackpad 2 (Wireless, Rechargable) - https://amzn.to/36ltimu ○ Apple MacBook Pro - https://amzn.to/30iSvKE ○ All-In One Printer - https://amzn.to/34etmSi ○ Apple AirPods Pro - https://amzn.to/2GpVYQf ○ My new favorite Apple Watch - https://amzn.to/2EIIUFd // MY FAVORITE BOOKS: ○ Introduction to Algorithms - https://amzn.to/36hxHXD ○ Designing Data-Intensive Applications - https://amzn.to/2S7snOg ○ Head First Java - https://amzn.to/2ScLDKa ○ Design Patterns - https://amzn.to/2SaGeU2 Follow me on Github for complete LeetCode solutions: https://github.com/fishercoder1534/Leetcode Support me on Patreon: https://www.patreon.com/fishercoder My ENTIRE Programming Equipment and Computer Science Bookshelf: https://www.amazon.com/shop/fishercoder And make sure you subscribe to my channel! Your comments/thoughts/questions/advice will be greatly appreciated! #softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures

Download

1 formats

Video Formats

360pmp418.4 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

LeetCode 21: Merge Two Sorted Lists ITERATIVELY - Interview Prep Ep 61 | NatokHD