목록js (166)
N
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..

104. Maximum Depth of Binary Tree Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 3 Example 2: Input: root = [1,null,2] Output: 2 Example 3: Input: root = [] Output: 0 Example 4: Input: root = [0] Output..
https://programmers.co.kr/learn/courses/30/lessons/64063?language=javascript 코딩테스트 연습 - 호텔 방 배정 programmers.co.kr map과 union find를 조합해서 풀이. 우선 room number가 배정되었는지 확인하기 위한 map을 선언. room_number를 for문으로 순회하여 해당 방이 배정되었는지 find 함수를 통해 찾는다. find 함수 전달받은 number를 key로 하여 map을 탐색. 만약 undefined가 나온다면 배정이 안된 상태를 뜻하기 때문에 number를 key, number + 1을 value로 하여 저장한 후, number를 리턴한다. 그렇지 않고 이미 방 배정이 되어 있다면 해당 value..
https://programmers.co.kr/learn/courses/30/lessons/42861?language=javascript 코딩테스트 연습 - 섬 연결하기 4 [[0,1,1],[0,2,2],[1,2,5],[1,3,1],[2,3,8]] 4 programmers.co.kr union & find를 이용한 문제 풀이. 우선 parent를 저장하는 n 크기의 배열을 선언하여 자기 자신을 가리키도록 한다. 이후 costs를 비용의 오름차순으로 정렬. for문으로 costs를 순회. costs[0]은 출발점, costs[1]은 도착점이므로 unionFind 함수에 각 노드 번호를 전달해 parent를 찾는다. 만약 n번의 노드의 부모가 n이라면 그대로 n을 리턴해주고, 그렇지 않다면 루트의 번호를 계..
811. Subdomain Visit Count A website domain "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com" and at the lowest level, "discuss.leetcode.com". When we visit a domain like "discuss.leetcode.com", we will also visit the parent domains "leetcode.com" and "com" implicitly. A count-paired domain is a domain that has one o..
560. Subarray Sum Equals K Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k. Example 1: Input: nums = [1,1,1], k = 2 Output: 2 Example 2: Input: nums = [1,2,3], k = 3 Output: 2 Constraints: 1
https://leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - 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을 활용한 문제 풀이. s의 각 문자부터 시작하면서 map을 선언한다. substring을 추출하는데, 중복되는 문자가 없어야 한다. 그렇기 때문에 이중 for문을 사용하여 substri..