본문 바로가기

algorithm

(14)
선형 보간법 (Linear Interpolation) 선형 보간법(Linear Interpolation) 이란?선형 보간법은 두 점 사이의 값을 추정하는 방법입니다. 이 두 점 사이에 직선을 그린 후, 직선 위의 임의의 점에서 값을 예측합니다. 쉽게 말하면, 두 지점 사이에서 값이 선형적으로(일직선 형태로) 변화한다고 가정하고, 그 사이에 있는 값들을 계산하는 방법입니다.예시로 개념 이해하기만약 어떤 사람이 2시간 동안 달렸다고 생각해봅시다.1시간 동안은 5km를 달렸고,2시간이 지났을 때는 10km를 달렸다고 가정합니다.이 두 지점 사이에 있는 1시간 30분이 지났을 때, 이 사람이 몇 km를 달렸을지 추정하려고 합니다. 이때 선형 보간법을 사용하여 그 중간 값을 쉽게 계산할 수 있습니다. 1시간에서 2시간까지 거리는 일직선으로 증가한다고 가정하고, 이 ..
[leetcode][hard] Maximum Profit in Job Scheduling We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i]. You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range. If you choose a job that ends at time X you will be able to start another job that starts at time X. Exampl..
[leetcode] 588. Design In-Memory File System Design an in-memory file system to simulate the following functions: ls: Given a path in string format. If it is a file path, return a list that only contains this file's name. If it is a directory path, return the list of file and directory names in this directory. Your output (file and directory names together) should in lexicographic order. mkdir: Given a directory path that does not exist, y..
[leetcode] Exclusive Time of Functions On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1. Function calls are stored in a call stack: when a function call starts, its ID is pushed onto the stack, and when a function call ends, its ID is popped off the stack. The function whose ID is at the top of the stack is the current function being executed. Each time a function ..
[leetcode] 1423. Maximum Points You Can Obtain from Cards There are several cards arranged in a row, and each card has an associated number of points The points are given in the integer array cardPoints. In one step, you can take one card from the beginning or from the end of the row. You have to take exactly k cards. Your score is the sum of the points of the cards you have taken. Given the integer array cardPoints and the integer k, return the maximu..
[leetcode] 210. Course Schedule II There are a total of n courses you have to take labelled from 0 to n - 1. Some courses may have prerequisites, for example, if prerequisites[i] = [ai, bi] this means you must take the course bi before the course ai. Given the total number of courses numCourses and a list of the prerequisite pairs, return the ordering of courses you should take to finish all courses. If there are many valid answe..
[leetcode] 211. Design Add and Search Words Data Structure Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: WordDictionary() Initializes the object. void addWord(word) Adds word to the data structure, it can be matched later. bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may conta..
[leetcode] 211. Design Add and Search Words Data Structure Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: WordDictionary() Initializes the object. void addWord(word) Adds word to the data structure, it can be matched later. bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may conta..
[leetcode] 573. Squirrel Simulation There's a tree, a squirrel, and several nuts. Positions are represented by the cells in a 2D grid. Your goal is to find the minimal distance for the squirrel to collect all the nuts and put them under the tree one by one. The squirrel can only take at most one nut at one time and can move in four directions - up, down, left and right, to the adjacent cell. The distance is represented by the numb..
3. Longest Substring Without Repeating Characters Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the ans..