随笔分类 - Binary Tree
发表于 2020-07-11 18:13阅读:240评论:0推荐:0
摘要:前序遍历的非递归实现 1 void PreOrder2(BTNode *root) { 2 BTNode *p = root; 3 stack<BTNode *> S; 4 while (p != NULL || !S.empty()) { 5 if (p) { 6 cout << p->val <
阅读全文 »
发表于 2018-12-04 12:27阅读:663评论:0推荐:0
摘要:Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive). The binary search tree is g
阅读全文 »
发表于 2018-12-04 11:59阅读:254评论:0推荐:0
摘要:Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Exa
阅读全文 »
发表于 2018-12-01 11:04阅读:294评论:0推荐:0
摘要:Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes. Example: Input: 1 \ 3 / 2 O
阅读全文 »
发表于 2018-11-30 22:34阅读:296评论:0推荐:0
摘要:Given an array nums, we call (i, j) an important reverse pair if i < j and nums[i] > 2*nums[j]. You need to return the number of important reverse pai
阅读全文 »
发表于 2018-11-29 22:34阅读:438评论:0推荐:0
摘要:Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a list of disjoint intervals. For exampl
阅读全文 »
发表于 2018-11-29 21:13阅读:285评论:0推荐:0
摘要:Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the eleme
阅读全文 »
发表于 2018-11-28 21:18阅读:238评论:0推荐:0
摘要:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smal
阅读全文 »
发表于 2018-11-27 15:26阅读:178评论:0推荐:0
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is d
阅读全文 »
发表于 2018-11-27 13:09阅读:176评论:0推荐:0
摘要:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the dep
阅读全文 »
发表于 2018-11-26 22:11阅读:192评论:0推荐:0
摘要:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and
阅读全文 »
发表于 2018-11-24 22:30阅读:191评论:0推荐:0
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia
阅读全文 »
发表于 2018-11-24 22:11阅读:294评论:0推荐:0
摘要:Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.
阅读全文 »
发表于 2018-11-24 18:31阅读:181评论:0推荐:0
摘要:Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th
阅读全文 »
发表于 2018-11-24 12:22阅读:217评论:0推荐:0
摘要:Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the
阅读全文 »
发表于 2018-11-24 11:40阅读:193评论:0推荐:0
摘要:Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Retu
阅读全文 »
发表于 2018-11-24 10:51阅读:228评论:0推荐:0
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n
阅读全文 »
发表于 2018-11-24 09:58阅读:220评论:0推荐:0
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only
阅读全文 »
发表于 2018-11-23 20:45阅读:306评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-23 15:50阅读:173评论:0推荐:0
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes
阅读全文 »