[LeetCode][Python3] 21. Merge Two Sorted Lists
                2018. 9. 11. 21:09 |
                
                    프로그래밍/LeetCode
                
            
            
            
        Problem :
https://leetcode.com/problems/merge-two-sorted-lists/description/
My Solution :
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
class Solution:
    def mergeTwoLists(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        head = ListNode(0)
        current = head
        while l1 and l2:
            if l1.val < l2.val:
                current.next = l1
                l1 = l1.next
            else:
                current.next = l2
                l2 = l2.next
            current = current.next
        current.next = l1 or l2
        return head.next
Comment :
내가 한번에 풀어서 실수 없이 통과하는 경우는 별로 없었는데, 이 문제는 한번에 통과했다. None 입력 말고는 딱히 주의할만한 Edge Case가 없어서 그런 듯.
'프로그래밍 > LeetCode' 카테고리의 다른 글
| [LeetCode][Python3] 28. Implement strStr() (0) | 2018.09.12 | 
|---|---|
| [LeetCode][Python3] 27. Remove Element (0) | 2018.09.11 | 
| [LeetCode][Python3] 26. Remove Duplicates from Sorted Array (0) | 2018.09.11 | 
| [LeetCode][Python3] 7. Reverse Integer (0) | 2018.09.11 | 
| [LeetCode][Python3] 20. Valid Parentheses (0) | 2018.09.11 | 
| [LeetCode][Python3] 14. Longest Common Prefix (0) | 2018.09.11 | 
| [LeetCode][Python3] 13. Roman to Integer (0) | 2018.09.11 | 
| [LeetCode][Python3] 9. Palindrome Number (0) | 2018.09.10 | 
최근에 달린 댓글 최근에 달린 댓글