[LeetCode] 206. Reverse Linked List
# 문제 설명 Given the head of a singly linked list, reverse the list, and return the reversed list. 이 문제는 링크드 리스트가 주어졌을 때 주어진 리스트의 역순 리스트를 반환하는 문제이다. # 예시 Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Input: head = [1,2] Output: [2,1] Input: head = [] Output: [] 이 문제를 보았을 때 쉽게 풀 수 있을 것이라 생각했지만 비효율적인 방법만 떠올랐다. class Solution: def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: vals..
2023. 2. 4.
[LeetCode] 21. Merge Two Sorted Lists
# 문제 설명 You are given the heads of two sorted linked lists list1 and list2. Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list. Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: Input: list1 = [], list2 = [] Output: [] Example 3: Input: list1 = [], list2 = [0] Ou..
2023. 2. 4.