본문 바로가기

tree14

[LEET CODE] 208. Implement Trie (Prefix Tree) # Problem A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. Implement the Trie class: Trie() Initializes the trie object. void insert(String word) Inserts the string word into the trie. boolean search(String word) Re.. 2021. 5. 26.
[LEET CODE] 105. Construct Binary Tree from Preorder and Inorder Traversal # Problem 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. Constraints: 1 2021. 5. 24.
[LEET CODE] 938. Range Sum of BST # Problem Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high]. Constraints: The number of nodes in the tree is in the range [1, 2 * 104]. 1 L: stack.append(node.left) if node.val < R: stack.append(node.right) if L L: stack.append(node.left) if node.val < R: stack.append(node.right) if L O.. 2021. 5. 24.
[LEET CODE] 108. Convert Sorted Array to Binary Search Tree # Problem Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. Constraints: 1 2021. 5. 19.
❗️[LEET CODE] 310. Minimum Height Trees # Problem A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes ai and bi in the tree, you can choose any node of the tree .. 2021. 4. 20.
[LEET CODE] 297. Serialize and Deserialize Binary Tree # Problem 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/deserial.. 2021. 4. 20.
반응형