[Leetcode 110] - Balanced Binary Tree w/ Python
Given a binary tree, determine if it is height-balanced 이진 트리가 주어졌을때 균형 이진 트리인지 확인해야 되는 문제 https://leetcode.com/problems/balanced-binary-tree/description/ Example 1: Input: root = [3,9,20,null,null,15,7] Output: true Example 2: Input: root = [1,2,2,3,3,null,null,4,4] Output: false Example 3: Input: root = [] Output: true 함수 아웃풋: [ 현재까지 탐색한 부분이 균형인가 확인 , 현재까지 탐색한 길이 확인] 1. DFS를 통해 Root 노드가 None일때..
2024. 4. 9.
[Leetcode 226] - Invert Binary Tree w/ Python
Given the root of a binary tree, invert the tree, and return its root. 이진 트리의 루트가 주어졌을때 역순으로 바꿔 리턴하는 문제 https://leetcode.com/problems/invert-binary-tree/description/ Example 1: Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: Input: root = [2,1,3] Output: [2,3,1] Example 3: Input: root = [] Output: [] 재귀를 통해 쉽게 풀 수 있는 문제 1. 루트 노드의 왼쪽 오른쪽 노드를 바꾼다 2. 재귀를 통해 왼쪽 오른쪽 노드로 들어가서 반복한다 cla..
2024. 4. 8.
[Leetcode 23] - Merge k Sorted Lists w/ Python
문제 You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. 오름차순으로 정렬 되어 있는 연결 리스트의 배열이 주어졌다. 오름차순으로 정렬 되어 있는 한개의 연결 리스트로 만들어라! https://leetcode.com/problems/merge-k-sorted-lists/ 예시 Example 1: Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists a..
2024. 4. 8.