문제 링크 Subsets - 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 문제 유형 백트래킹(Backtracking) 문제 풀이 해당 문제는 중복되지 않는 숫자들로 이루어진 배열이 주어지고, 이 숫자들로 만들 수 있는 부분집합을 배열로 반환하는 문제이다. 가능한 후보들을 모두 탐색해야 부분집합을 구할 수 있기에 가능한 후보들을 찾다가 조건을 만족하지 않으면 다시 되돌아가는 백트래킹 방식을 사용할 수 있다. 해당 문제가 재귀적으로 어떻게 동작하는지 자세히 살펴보..
문제 링크 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 문제 유형 다이나믹 프로그래밍 (Dynamic Programming) 문제 풀이 해당 문제는 n x m 매트릭스를 나타내는 2차원 배열이 주어지고, (0,0)에서 (n, m)으로 가는 경로의 최소 합을 구하는 문제이다. 경로 이동은 현재 원소에서 오른쪽이나 아래로만 할 수 있다. 그러므로 각 원소의 이전 경로의 원소는 왼쪽에 있거나 위에 있다. 이는 왼쪽 원소까지의 최소 ..
문제 링크 Min Cost Climbing Stairs - 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 문제 유형 다이나믹 프로그래밍(Dynamic Programming) 문제 풀이 해당 문제는 각 계단을 올랐을 때의 비용을 나타내는 숫자 배열이 주어지고, 계단을 다 올랐을 때의 최소 비용을 구하는 문제이다. 계단은 1칸 또는 2칸을 오를 수 있다. 생각해보면 출발 지점의 비용은 없으므로 Index 0과 Index 1 계단까지 올라가는 최소 비용은 0이다. 그..
문제 링크 Top K Frequent Words - 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 Top K Frequent Elements - 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 문제 유형 해쉬 맵, 정렬 ..
문제 링크 First Unique Character in a 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 문제 유형 해쉬 맵(Hash Map) 문제 풀이 이 문제는 문자열이 주어지고, 문자열에서 처음으로 중복되지 않는 문자의 인덱스를 반환하는 문제이다. 해당 문제는 해쉬 맵을 사용하면 쉽게 해결할 수 있다. 먼저, 각 문자를 확인하면서 키를 각 문자를 저장하고, 값에 중복된 횟수를 저장하는 해쉬 맵을 만든다. 다시 각 문자를 확인하면서 해당 문..
문제 링크 Two 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 문제 유형 배열, Hash Map 문제 풀이 해당 문제는 숫자 배열과 target 값이 주어지고 배열 내 임의의 두 숫자를 더하면 target 값이 되는 두 숫자의 인덱스를 배열 형태로 출력하는 문제이다. 이 문제는 해시 테이블을 이용하면 O(n)의 시간복잡도로 문제를 해결할 수 있다. 먼저, 해시 테이블 Map을 생성하고, 배열을 순차적으로 접근한다. 만약 현재 숫자가 해시 테이블에 저..
문제 링크 Remove All Adjacent Duplicates 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 Remove All Adjacent Duplicates in String II - 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..
문제 링크 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 문제 유형 투 포인터 (Two Pointer) 문제 풀이 해당 문제는 중복되는 문자가 없는 가장 긴 서브 스트링을 찾아 반환하는 문제이다. 단순히 생각해보면 이중 for문으로 substring을 차례대로 만들고, 중복되는 문자 체크와 최대 길이를 저장하며 문제를 해결할 수 있을 것이다. 그러나 이는 O(n^2)의 시간복..