[leetcode 21] Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists. 오름차순순으로 리스트를 합치자. Example 1: Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: Input: l1 = [], l2 = [] Output: [] Example 3: Input: l1 = [], l2 = [0] Output: [0] 풀이: -포인터만 잘 활용한다면 쉬운 문제이다. - 난이도: easy /** * Definition for singly-lin..
2020. 10. 17.
[leetcode 19] Remove Nth Node From End of List
Given the head of a linked list, remove the nth node from the end of the list and return its head. Follow up: Could you do this in one pass? 끝에서 n번째 노드를 제거하는 문제 Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] 풀이: - 투포인터를 사용하면 한 번에 가능하다는데 귀찮아서 안해봤다. 나중에 해봐야지 - linked list를 이용한 더미 포인터를 만들..
2020. 10. 15.