목록Leet Code 알고리즘 (179)
N
https://leetcode.com/problems/snapshot-array/ Snapshot Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Map을 이용한 문제 풀이. 생성자가 호출될 때 전체 스냅샷이 저장될 snapshots(Map), 현재 스냅샷을 나타내는 array(Map), 현재 스냅 Id를 나타내는 snapId를 선언한다. set(index, val) 함수. 현재 스냅샷에 key: index, value: val 로 저장한다. sna..
https://leetcode.com/problems/minesweeper/ Minesweeper - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com DFS를 이용한 문제풀이. 탐색에 필요한 변수와 배열을 미리 선언한다. 또한, 탐색 시 board의 범위를 벗어나는지 검사하는 checkRange도 정의. dfs함수에는 탐색할 x, y 좌표를 받아 8방향을 검사하면 된다. dfs() 시작은 board[x][y] 좌표에 방문했다는 표시로 visited[x][y] = ..
https://leetcode.com/problems/reorganize-string/submissions/ Reorganize String - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com const asc = (a, b) => { if(a[1] === b[1]){ return a[0] - b[0]; } return b[1] - a[1]; } const reorganizeString = (s) => { const map = new Map(); const ans..
https://leetcode.com/problems/k-closest-points-to-origin/ K Closest Points to Origin - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com array 배열과 answer 배열을 선언. points 배열을 순회하면서 array에 유클리드 거리와 인덱스를 넣어준다. 유클리드 거리와 인덱스가 저장된 array 배열을 거리의 오름차순으로 정렬. k개 만큼 answer에 답을 넣어주면 된다. /** * @pa..
https://leetcode.com/problems/rearrange-words-in-a-sentence/ Rearrange Words in a Sentence - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어진 text를 split() 함수를 통해 공백을 구분자로 하여 나눈다. 이후 나눠진 단어를 단어 길이의 오름차순으로 정렬하도록 한다. 정렬된 단어를 join 함수를 통해 공백을 구분자로 하여 합친다. 리턴은 조인된 한 문장이며, 첫 글자는 대문자여야..

38. Count and Say The count-and-say sequence is a sequence of digit strings defined by the recursive formula: countAndSay(1) = "1" countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1), which is then converted into a different digit string. To determine how you "say" a digit string, split it into the minimal number of groups so that each group is a contiguous section a..
200. Number of Islands Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. Example 1: Input: grid = [ ["1","1","1","1","0"], ["1","1","0","1","0"], ["1","..

113. Path Sum II Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references. A root-to-leaf path is a path starting from the root and ending at any leaf node. A leaf is a node with no children. Example 1: Input: root = [5,4,8,1..