본문 바로가기

백트래킹9

[Leetcode 51] - N-Queens w/ Python The 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, respectively. n x n크기.. 2024. 4. 16.
[Leetcode 17] - Letter Combinations of a Phone Number w/ Python Given 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. 전화기에 있는 숫자 조합이 주어졌을 경우 2~9의 각 숫자에 알맞은 글자로 만들수 있는 조합을 찾는 문제 https://leetcode.com/problems/letter-combinations-of-a-p.. 2024. 4. 15.
[Leetcode 131] - Palindrome Partitioning w/ Python Given a string s, partition s such that every substring of the partition is a palindrome . Return all possible palindrome partitioning of s. s라는 string이 주어졌을때 글자를 분할해서 회문이 되는 모든 경우를 찾는 문제 https://leetcode.com/problems/palindrome-partitioning/description/ Example 1: Input: s = "aab" Output: [["a","a","b"],["aa","b"]] Example 2: Input: s = "a" Output: [["a"]] 백트래킹으로 해결 가능한 문제 모든 글자에서 시작해 각각 다음에 오는.. 2024. 4. 13.
[Leetcode 40] - Combination Sum II w/ Python Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target. Each number in candidates may only be used once in the combination. Note: The solution set must not contain duplicate combinations. 숫자들로 이루어진 배열과 목표 (타겟) 숫자가 주어진다 배열들에 있는 숫자 합으로 목표에 도달할 수 있는 조합을 찾는 문제 배열에 있는 숫자는 한번씩 사용 가능하고 같은 조합.. 2024. 4. 13.
[Leetcode 90] - Subsets II Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. 중복된 숫자가 있는 배열이 주어졌을때 가능한 하위 집합을 찾는 문제 리턴하는 배열에는 중복된 집합을 포함시킬수 없다 https://leetcode.com/problems/subsets-ii/description/ Example 1: Input: nums = [1,2,2] Output: [[],[1],[1,2],[1,2,2],[2],[2,2]] Example 2: Input.. 2024. 4. 12.
[Leetcode 46] - Permutations w/ Python Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. 배열이 주어졌을때 순열을 찾는 문제 https://leetcode.com/problems/permutations/description/ Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: Input: nums = [0,1] Output: [[0,1],[1,0]] Example 3: Input: nums = [1] Output: [[1]] 답은 매우 쉽죠? class.. 2024. 4. 12.
[Leetcode 39] - Combination Sum w/ Python Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different. The test.. 2024. 4. 12.
[Leetcode 78] - Subsets w/ Python Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. 숫자 배열이 주어졌을때 가능한 모든 하위 집합을 리턴 중복된 집합을 배제해야된다 https://leetcode.com/problems/subsets/description/ Example 1: Input: nums = [1,2,3] Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] Example 2: Input: nums = [0] Output: [.. 2024. 4. 12.
[Leetcode 211] - Design Add and Search Words Data Structure w/ Python Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: ● WordDictionary() Initializes the object. ● void addWord(word) Adds word to the data structure, it can be matched later. ● bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may.. 2024. 4. 11.
반응형