[Leetcode 230] - Kth Smallest Element in a BST w/ Python
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. 이진 탐색 트리가 주어졌을때 트리에서 k 번째 작은 숫자를 리턴하는 문제 https://leetcode.com/problems/kth-smallest-element-in-a-bst/description/ Example 1: Input: root = [3,1,4,null,2], k = 1 Output: 1 Example 2: Input: root = [5,3,6,2,4,null,null,1], k = 3 Output: 3 이진 탐색 트리인 만큼 중위 순..
2024. 4. 10.
[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.