[Leetcode 199] - Binary Tree Right Side View w/ Python
Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. 이진 트리 우측, 조금 거리가 있는곳에서 바라본다고 생각해보자 우측에서 보이는 노드를 위에서 아래로 배열에 저장해서 리턴 https://leetcode.com/problems/binary-tree-right-side-view/description/ Example 1: Input: root = [1,2,3,null,5,null,4] Output: [1,3,4] Example 2: Input: root = [1,null,3] Outpu..
2024. 4. 10.
[Leetcode 102] - Binary Tree Level Order Traversal w/ Python
Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). 이진 트리가 주어졌을때 각 레벨 순서 순회의 값을 찾아서 리턴하는 문제 https://leetcode.com/problems/binary-tree-level-order-traversal/description/ Example 1: Input: root = [3,9,20,null,null,15,7] Output: [[3],[9,20],[15,7]] Example 2: Input: root = [1] Output: [[1]] Example 3: Input: root = [] O..
2024. 4. 9.
[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.