본문 바로가기

Algorithm/알고리즘 문제풀이92

LeetCode 77(Combinations, java) 0. 문제 https://leetcode.com/problems/combinations/ Combinations - 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 1. 문제 설명 - 문제에서 정수 n과 k가 주어진다. - 1부터 n까지의 수를 이용하여 중복 없이 k개의 짝을 이루는 모든 조합을 구하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 이 문제는 전형적인 back tracking 문제다. - back tracking은 정답에 부합하는 .. 2022. 5. 6.
LeetCode 994(Rotting Orange, java) 0. 문제 https://leetcode.com/problems/rotting-oranges/ Rotting Oranges - 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 1. 문제 설명 - 문제에서 이중 배열(grid)이 주어진다. - 이중 배열에는 빈 공간(= 0), 신선한 오렌지(= 1), 상한 오렌지(= 2)와 같은 3가지 값이 저장되어있다. - 상한 오렌지에 인접한 신선한 오렌지는 1분이 지날 때마다 상한다. - 인접한 오렌지 중 상한 오렌지가 존재하.. 2022. 5. 6.
LeetCode 542(01 Matrix, java) 0. 문제 https://leetcode.com/problems/01-matrix/ 01 Matrix - 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 1. 문제 설명 - 문제에서 이중 배열(mat)이 주어진다. - 이중 배열의 원소 중 1이 입력된 위치를 찾고, 해당 위치부터 0까지의 최단 거리를 찾아낸다. - 최단 거리가 잘못 입력된 원소를 수정하여 올바른 값을 가진 이중 배열을 반환하는 것이 이 문제의 핵심이다. 2. 문제 해설 - 글쓴이는 이 문제를 풀기.. 2022. 4. 30.
LeetCode 116(Populating Next Right Pointers in Each Node, java) 0. 문제 https://leetcode.com/problems/populating-next-right-pointers-in-each-node/ Populating Next Right Pointers in Each Node - 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 1. 문제 설명 - 문제에서 완전 이진트리(root)가 주어진다. - 모든 노드는 next 속성이 있는데, 이는 우측 노드를 가리키는 포인터 역할을 한다. - 모든 노드의 next 값은 nul.. 2022. 4. 29.
LeetCode 617(Merge Two Binary Trees, java) 0. 문제 https://leetcode.com/problems/merge-two-binary-trees/ Merge Two Binary Trees - 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 1. 문제 설명 - 문제에서 이진트리 2개(root1, root2)가 주어진다. - 두 이진트리를 병합하여 하나의 이진트리를 반환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 이 문제는 두 트리의 노드를 탐색하여, 각 노드의 값을 병합하는 과정을.. 2022. 4. 28.
LeetCode 695(Max Area of Island, java) 0. 문제 https://leetcode.com/problems/max-area-of-island/ Max Area of Island - 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 1. 문제 설명 - 문제에서 이중 배열(= grid)이 주어진다. - 이중 배열의 값으로 1과 0이 주어지는데, 0은 바다를 의미하고 1은 땅을 의미한다. - 상하좌우로 연결된 1의 값을 계산하여, 그중 가장 큰 값(= 가장 큰 땅)을 반환하는 것이 문제의 핵심이다. - 이 문제는.. 2022. 4. 27.
LeetCode 733(Flood Fill, java) 0. 문제 https://leetcode.com/problems/flood-fill/ Flood Fill - 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 1. 문제 설명 - 문제에서 이중 배열(image)과 시작점이 되는 row(= sr)와 column(= sc) 위치, 새로운 색상(= newColor)이 주어진다. - 문제에서 제공하는 시작 위치의 값과 시작 위치를 기준으로 4방향에 존재하는 요소의 값이 동일하다면, 해당 요소의 값을 newColor로 대체하.. 2022. 4. 27.
LeetCode 567(Permutation in String, java) 0. 문제 https://leetcode.com/problems/permutation-in-string/ Permutation in 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 1. 문제 설명 - 문제에서 2개의 문자열(s1, s2)이 주어진다. - s1을 구성하는 문자의 순열 중 하나라도 s2를 구성한다면 true를 반환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 순열을 어떻게 구할 것인지에 대해서 생각해보자. -.. 2022. 4. 27.
LeetCode 3(Longest Substring Without Repeating Characters, java) 0. 문제 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 1. 문제 설명 - 문제에서 문자열(s)이 주어진다. - 문자열을 탐색하여 중복 없이 구성된 내부 문자열 중 가장 긴 길이를 찾는 것이 핵심이다. 2. 문제 해설 a) 첫 번째 접근.. 2022. 4. 26.