[Leetcode/파이썬] 112. Path Sum
Path SumGiven the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.A leaf is a node with no children. Example 1:Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22Output: trueExplanation: The root-to-leaf path with the target sum is shown.Example 2:Input: root = [..
더보기
[Leetcode/파이썬] 215. Kth Largest Element in an Array
Kth Largest Element in an ArrayGiven an integer array nums and an integer k, return the kth largest element in the array.Note that it is the kth largest element in the sorted order, not the kth distinct element.Can you solve it without sorting? Example 1:Input: nums = [3,2,1,5,6,4], k = 2Output: 5Example 2:Input: nums = [3,2,3,1,2,4,5,5,6], k = 4Output: 4 Constraints:1 5-104 4 class Solution: ..
더보기
[코딩 테스트 합격자 되기 파이썬 - 3주차]백트래킹
개념1. 백트래킹(Backtracking) 알고리즘의 작동 원리를 설명하고, 상태 공간 트리(State Space Tree) 개념과 연관 지어 설명해주세요. 주로 어떤 방식으로 구현되며 (예:재귀), 그 이유는 무엇인가요?더보기백트래킹 알고리즘은 어떤 가능성이 없는 곳을 알아보고 되돌아 가는 것입니다. 책을 살펴보면, 시작점(루트)은 빈 리스트로 시작을 한다. 숫자가 4개가 포함되어 있으니, level 0 -> 1로 내려가면, 빈 리스트에 하나의 숫자씩 차지하게 된다. res = [[1], [2], [3], [4]]숫자 2개의 조합을 완성해야 하므로, 이 아래로 선택한 숫자를 제외한 3개씩 노드를 가지게 되면 총 12개 조합이 완성되고, 이를 모두 통과하게 되면 O(12)이 될 것이다. ($O(N^{2}..
더보기