본문 바로가기

Python41

[Leetcode 297] - Serialize and Deserialize Binary Tree w/ Python Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment. Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization al.. 2024. 4. 11.
[Leetcode 124] - Binary Tree Maximum Path Sum w/ Python A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node's values in the path. Given the root of a binary tree, return the maximum path sum of any non-empty path. 이진 트리가 주.. 2024. 4. 11.
[Leetcode 105] - Construct Binary Tree from Preorder and Inorder Traversal w/ Python Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree. 전위 순회와 중위 순회가 주어진다면, 이를 통해 이진 트리를 만드는 문제 https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description/ Example 1: Input: preorder = [3,9,20,15,7], inorder = [9,3,.. 2024. 4. 11.
[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 98] - Validate Binary Search w/ Python Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: ● The left subtree of a node contains only nodes with keys less than the node's key. ● The right subtree of a node contains only nodes with keys greater than the node's key. ● Both the left and right subtrees must also be binary search trees. 이진 트리가 주어졌을때 이진 탐색 트리인지 확인하는 문제 각 .. 2024. 4. 10.
[Leetcode 1448] - Count Good Nodes in Binary Tree w/ Python Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in the binary tree. 이진 트리가 주어졌을때 다음으로 탐색할 노드의 값이 현재 위치한 노드의 값보다 큰 숫자를 파악해서 리턴 ※ Root 노드는 언제나 포함된다 https://leetcode.com/problems/count-good-nodes-in-binary-tree/description/ Example 1: Input: root = [3,1,4,3,null,1,5] Output: 4 .. 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.
[Leetcode 235] - Lowest Common Ancestor of a Binary Search Tree w/ Python Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).” 이진 탐색 트리와 2개의 노드가 주어진다. 최소 공통 조상을 찾아서 리턴 결국 두개의 노드에서 가장 가까운 .. 2024. 4. 9.
반응형