반응형 전체 글84 [DSA][Linked List] 10. Merge k Sorted Lists LeetCode 23 10. Merge k Sorted ListsYou are given an array of k linked-lists lists, each linked-list is sorted in ascending order.Merge all the linked-lists into one sorted linked-list and return it. [질문하기]- 입력으로 빈 리스트가 있을 수 있나요?- Output을 새로 만들어서 반환해야 하나요, 아니면 기존 노드들을 재사용해야 하나요? [아이디어]- 두 연결리스트씩 나누어 병합하자. [풀이 1] Linked Listclass Solution: def merge2Lists(self, list1, list2): head = .. 2025. 7. 7. [DSA][Linked List] 09. LRU Cache LeetCode 146 09. LRU CacheDesign a data structure that follows the constraints of a Least Recently Used (LRU) cache.Implement the LRUCache class:- LRUCache(int capacity) Initialize the LRU cache with positive size capacity.- int get(int key) Return the value of the key if the key exists, otherwise return -1.- void put(int key, int value) Update the value of the key if the key exists. Otherwise,.. 2025. 7. 6. [DSA][Linked List] 08. Find the Duplicate Number LeetCode 287 08. Find the Duplicate NumberGiven an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.There is only one repeated number in nums, return this repeated number.You must solve the problem without modifying the array nums and using only constant extra space. [아이디어]- 인덱스와 값의 관계를 연결 리스트의 구조로 응용하자. [풀이 1] Linked Listclass Solution: d.. 2025. 7. 5. [DSA][Linked List] 07. Add Two Numbers LeetCode 2 07. Add Two NumbersYou are given two non-empty linked lists representing two non-negative integers.The digits are stored in reverse order, and each of their nodes contains a single digit.Add the two numbers and return the sum as a linked list.You may assume the two numbers do not contain any leading zero, except the number 0 itself. [질문하기]- 입력으로 주어지는 두 연결 리스트는 항상 최소 하나의 노드를 가지나요? YES.. 2025. 7. 4. 이전 1 2 3 4 5 6 ··· 21 다음