[LeetCode][python3]0021. Merge Two Sorted Lists

  1. A Common Solution
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
dummy = copy = ListNode(None)
while l1 and l2:
if l1.val < l2.val:
dummy.next = l1
l1 = l1.next
else:
dummy.next = l2
l2 = l2.next
dummy = dummy.next
dummy.next = l1 or l2
return copy.next

--

--

--

HI I’m N2I. Now a SWE in Taiwan. Check out more about me in https://nzi2020.blogspot.com/ or contact via email: nayzi9999@gmail.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to process multiple images and produce output files?

{UPDATE} Hot Dogs Cooking Chef Simulator Hack Free Resources Generator

The Ultimate Method of Creating Virtual Machine From VMDK in VMware

Perform Hashing in Computer Forensics

Declarative Idempotency

Machine learning and Big Data!

READ/DOWNLOAD$^ Building Scalable Cisco Internetworks (BSCI) (Authorized Self-Study Guide) (3rd…

My Experiences Getting Started with WebRTC

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
N2I

N2I

HI I’m N2I. Now a SWE in Taiwan. Check out more about me in https://nzi2020.blogspot.com/ or contact via email: nayzi9999@gmail.com

More from Medium

LeetCode #1332 | Remove Palindromic Subsequences

Creating a Stack in python : Data Structure : Stack : Chapter 2 : In Python

Basic Data Structure and Algorithms in Python

Leetcode Blind 75 practice — Contains duplicate