목록leet code (85)
N
https://leetcode.com/problems/minimum-path-sum/ Minimum Path Sum - 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 DP 알고리즘 이용. 주어진 grid의 크기는 m x n 이므로 각 변수에 length를 저장한다. dp 테이블은 grid와 마찬가지로 m x n의 크기로 선언하여 0으로 초기화한다. 시작점인 [0, 0]에서 끝점 [m - 1, n - 1]로 향하기 때문에 dp[0][0]은 grid[0][0]으로 ..
https://leetcode.com/problems/network-delay-time/ Network Delay Time - 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 다익스트라 알고리즘 활용. 우선 주어진 times 배열을 그래프로 나타내기 위해 n + 1 크기의 graph 2차원 배열을 선언. 또한, 노드 간 걸리는 시간을 dist 배열에 저장하기 위해 n + 1 크기의 1차원 배열을 선언하여 Infinity로 초기화한다. times를 순회하면서 노드를..
https://leetcode.com/problems/find-original-array-from-doubled-array/ Find Original Array From Doubled 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 Greedy 알고리즘 적용. changed 배열을 오름차순으로 정렬한 후 순회를 한다. 순회를 하면서 number배열에 changed[i]의 갯수를 카운팅한다. 다음 for문으로 다시 changed를 순회한다. 현재 ch..
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/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..