자료구조5 [Leetcode 146] - LRU Cache w/ Python 문제 Design 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, add the keyval.. 2024. 4. 7. [Leetcode 287] - Find the Duplicate Number w/ Python 문제 Given 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 uses only constant extra space. 주어진 리스트의 길이가 n + 1이다. 이 리스트에서 반복되는 숫자는 딱 한개인데 이를 리턴해야된다. 추가로 리스트에 있는 숫자를 수정할 수도 없고 O(1)에 비례되는 추가 메모리만 사용 가능하다. https.. 2024. 4. 7. [Leetcode 141] - Linked List Cycle w/ Python 문제 Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter. Return true if there is a cy.. 2024. 4. 7. [Leetcode 2] - Add Two Numbers w/ Python 문제 You 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. 두개의 연결 리스트가 주어졌을때 노드는 숫자의 각 자리를 표현한다. 리스트 1의 숫자는 342라고 가정하면 반대로 돌려서 243: 2 -.. 2024. 4. 7. [Leetcode 138] - Copy List with Random Pointer w/ Python Problem Description A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes s.. 2024. 4. 6. 이전 1 다음 반응형