본문 바로가기
반응형

분류 전체보기128

[DSA][Graph] 01. Number of Islands LeetCode 200 01. Number of IslandsGiven 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. [질문하기]- grid가 빈 배열일 수도 있나요? NO [아이디어]- grid를 순회하면서 값이 1인 칸을 발견하면, 해당 칸.. 2026. 2. 1.
[DSA][Backtracking] 10. N-Queens LeetCode 51 10. N-QueensThe n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space,.. 2026. 1. 31.
[DSA][Backtracking] 09. Letter Combinations of a Phone Number LeetCode 17 09. Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.Return the answer in any order.A mapping of digits to letters (just like on the telephone buttons) is given below.Note that 1 does not map to any letters. [질문하기]- 빈 digits이 주어질 수 있나요? NO [아이디어]- 이전까지 만든 문자열에 다음 digit의 문자.. 2026. 1. 11.
[DSA][Backtracking] 08. Palindrome Partitioning LeetCode 131 08. Palindrome PartitioningGiven a string s, split s into substrings where every substring is a palindrome.Return all possible lists of palindromic substrings.You may return the solution in any order. [아이디어]- 문자열을 앞에서부터 잘라가며 palindrome인지 확인하고, palindrome이면 재귀적으로 다음 부분을 탐색하며 분할을 완성하고, 반복되는 palindrome 판정은 DP 테이블로 O(1)에 확인한다. [풀이 1] Backtrackingclass Solution: def partition(self, .. 2026. 1. 4.