[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

Tech Transformation: The Cloud Dojo

Housekeeping Steps to Take After Installing Raspbian On A Raspberry Pi

Template design pattern and Strategy design pattern in Ruby.

Have you ever been asked to foretell the future about Project, Schedule, or Budget?

making use of decentralized autonomous orgs

working thru symbols for meaning. an absract art piece of an explorer

An Inside Look at Deploying Kubernetes on AWS

Use conditional tasks with Apache Airflow

ReactiveSearch + Appbase.io for hosted search backend — Part #5 of 11

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 Patterns Adventure 26 — Merge Two Binary Trees

My Calendar I

Hackerrank — Insert Node in linked list walkthrough #Python #Hackerrank

[LeetCode]#2042. Check if Numbers Are Ascending in a Sentence