Merge Two Sorted Lists
https://leetcode.com/problems/merge-two-sorted-lists/ ダミー Node を作って edge case の 空の Linked List が挿入されても大丈夫なようにする。 その後はループで l1 と l2 の val を比べ、 小さい値を tail.next に入れる。 その後、 next をずらす。 ループ後 l1, l2 のどちらかのリストが empty の場合、 Linked List に追加する必要があるので、 リストが empty か確認し、値があれば Linked List に追加する。 # Definition for singly-linked list. # class ListNode(object): # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution(object): def mergeTwoLists(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ dummy = ListNode() tail = dummy while l1 and l2: if l1....