본문 바로가기

Backtracking4

[LeetCode 풀이/python] 113. Path Sum II (medium) 문제 설명: 이진트리 root 와 정수 targetSum 이 주어졌을 때, 루트에서 단말 노드까지의 경로에 있는 모든 수의 합이 targetSum 과 같아지는 경로를 모두 리턴하시오. 단말 노드는 자식 노드를 갖지 않는 노드를 가리킴. (Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where each path's sum equals targetSum. A leaf is a node with no children.) 예시 1) 입력: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22 --> 출력: [[5,4,11,2],[5,8,4,5].. 2021. 3. 10.
[LeetCode 풀이/python] 79. Word Search (medium) 문제 설명: m x n 형태의 격자판 board 와 단어 word 가 주어졌을 때, 해당 격자판에 단어 word 가 존재하는지를 찾으시오. 단어 word 는 연속적으로 인접한 셀의 문자들로 구성될 수 있으며, 이 때 '인접한' 셀들은 수평 혹은 수직 방향으로 이웃한 것들이다. 동일한 문자 셀은 한 번을 초과하여 사용될 수 없다. (Given an m x n board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are horizontally or vertically neighboring. Th.. 2021. 3. 3.
[LeetCode 풀이/python] 47. Permutations II (medium) 문제 설명: 중복을 허용하는 숫자들의 집합 nums 가 주어졌을 때, 이를 통해 만들 수 있는 모든 고유한 순열(permutations) 조합을 리턴하시오. 리스트 내 조합의 순서는 무관하다. (Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.) 예시 1) 입력: nums = [1,1,2] --> 출력: [[1,1,2], [1,2,1], [2,1,1]] 예시 2) 입력: nums = [1,2,3] --> 출력: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 제한 조건: 1 2021. 2. 16.
[LeetCode 풀이/python] 39. Combination Sum (medium) 문제 설명: 구분되는 (중복이 없는) 정수 값으로 이루어진 배열 candidates 과 타겟 값 target 이 주어졌을 때, candidates 에서 선택한 숫자들을 더하여 타겟 값이 될 수 있는 고유한 숫자 조합을 모두 담은 리스트를 리턴하시오. 리스트 내 조합의 순서는 무관하며, candidates 에서 동일한 숫자가 선택될 수 있는 횟수에는 제한이 없다. 두 숫자 조합에서 선택된 숫자들 중 최소 하나라도 사용된 빈도가 다른 경우 이들은 고유 조합으로 간주된다. 주어진 입력에 대해 가능한 고유 숫자 조합의 개수는 150개를 넘지 않음이 보장된다. (Given an array of distinct integers candidates and a target integer target, return a .. 2021. 2. 15.