题目 Given n, how many structurally unique BSTs (binary search trees) that store values 1...n?
For example,Given n 3, there are a total of 5 unique BSTs. 1 3 3 2 1\ / / / \ \3 2 1 1 3 2/ …
题面 题解(二叉树的非递归中序遍历) 将整棵树的最左边的一条链压入栈中,每次取出栈顶元素,并记录,如果它有右子树,那么将右子树最左边压入压栈中 代码
/*** Definition for a binary tree node.* struct TreeNode {* int val…
查找某一点其左下方没有其他点的点的个数
其实是平衡数的添加删除查找的操作,用系统自带的multiset自动完成该任务
#include <bits/stdc.h>
using namespace std;
const int maxn1e550;
const int inf0x3f3f3f3f;
typedef long long ll;
struct Point
{int …
1115 Counting Nodes in a BST (30 分)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:
The left subtree of a node contains only nodes with keys less than or equal to the node’s key. The right subtree …
题目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: 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 greate…