LeetCode ๐Ÿ”๏ธ/Linked List

LeetCode ๐Ÿ”๏ธ/Linked List

23. Merge k Sorted Lists

Today, I solved the Merge K sorted Lists. Description: In this question, we are gonna merge several lists. And, the merged list should be sorted in order. Solution: This is the first part of solution. We will look into mergeLists() function later. If the gived lists are empty, we return None. While loop runs until the length of lists is over 1. We make the list for storing merged lists. Since we..

LeetCode ๐Ÿ”๏ธ/Linked List

141. Linked List Cycle

Today, I did the question: Linked List Cycle. Description: We should check whether cycle exist or not. head and pos is given. We can check the pos that which position is cycled back on the list. In example 1, 1st node is the returning node on the list. Then, how do we check the cycle on the list? The solution is similar to previous linked list question: We are gonna make the slow and fast pointe..

LeetCode ๐Ÿ”๏ธ/Linked List

143. Reorder List

Today, I solved "Reorder List." Description: It is hard to understand, but we are gonna reorder the list with rule. We can easily find the rule of the form: Before: L0 -> L1 -> L2 -> L3 -> L4 After: L0 -> L4 -> L1 -> L3 -> L2 Now, how can we change the list order without changing the value? We should make the other list to re-order the list. The recommendation is seperating the list as two lists..

LeetCode ๐Ÿ”๏ธ/Linked List

19. Remove Nth Node From End of List

Today, I solved "Remove Nth Node From End of List." Description: In this problem, we are gonna delete nth node from the end of the list. For example of case 1, we found the "4" is the 2nd node from the end of the list. But how can we delete and how can we know nth node from the end? Solution: 1. First, we are gonna make two pointers on the list: left and right. 2. "right" is "n" ahead of left. F..

LeetCode ๐Ÿ”๏ธ/Linked List

21. Merge Two Sorted Lists

Today, I solved the Merge Two Sorted Lists. Description: We have two lists, and we are gonna merge those two lists. The point is that we are gonna sort new list in non-decreasing order. Solution1: We make dummy node to avoid some error. And, we make curr node to know our location in both lists. Our while loop runs until we put every values in list1 and list2. If the value of list1 is less than l..

LeetCode ๐Ÿ”๏ธ/Linked List

206. Reverse Linked List

Today, I solved the Reverse Linked List. Description: In this problem, we reverse the order of single linked list. My idea was that changing the pointer to make reverse order. So, I thought I should change like this "1->2" as a "2->1" repeatedly. In the description of the question, we can see "A linked list can be reversed either iteratively or recursively." I'm not sure about this kind of quest..

KB0129
'LeetCode ๐Ÿ”๏ธ/Linked List' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก