
树
qq_30339595
人类,诗意地栖息在大地上。
展开
-
leetcode114 Flatten Binary Tree to Linked List
the purpose of this question is to let you recover the memory about post order tranverse.Just as the post order tranverse, to solve this problem,you have to solve the left subtree of the root and the...原创 2019-11-15 20:07:10 · 119 阅读 · 0 评论 -
判断一棵树是不是二叉排序树
# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def dfs(self,root...原创 2019-11-13 17:03:05 · 306 阅读 · 0 评论 -
leetcode 95 所有的二叉排序树
首先是递归的解法,# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def tre...原创 2019-11-13 14:48:00 · 151 阅读 · 0 评论 -
前中后序遍历非递归写法
class Solution: def inorderTraversal(self, root: TreeNode) -> List[int]: ans=[] stack=[] while len(stack)!=0 or root: while(root): ...原创 2019-11-25 17:14:30 · 372 阅读 · 0 评论 -
1135. Is It A Red-Black Tree (30)(红黑树)
1135. Is It A Red-Black Tree (30)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThere is a kind of balanced binary search tree named red-black tree in the data structure. It has the followi...原创 2018-03-14 16:31:47 · 302 阅读 · 0 评论 -
后序遍历的非递归写法
node *p=root; stack<node*>st; node *r=NULL; while(p||!st.empty()){ if(p){ st.push(p); p=p->l; } else{ p=st.top(); if(p->r&&p->r!=r) ...原创 2018-03-13 22:35:39 · 361 阅读 · 0 评论 -
PAT1127. ZigZagging on a Tree (30)(层次遍历last==f的模板)(中序和后序求树)
1127. ZigZagging on a Tree (30)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueSuppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determin...原创 2018-03-12 20:02:50 · 142 阅读 · 0 评论 -
PAT1123. Is It a Complete AVL Tree (30)(二叉平衡树模板)
//#include "stdafx.h"#include<cstdio>#include<iostream>#include<string>#include<algorithm>#include<set>#include<queue>using namespace std;const int maxn=4原创 2018-03-12 16:25:49 · 128 阅读 · 0 评论 -
最短路径(并查集+kruskal最小生成树)
时间限制:1秒 空间限制:65536K 热度指数:1293 算法知识视频讲解题目描述N个城市,标号从0到N-1,M条道路,第K条道路(K从0开始)的长度为2^K,求编号为0的城市到其他城市的最短距离输入描述:第一行两个正整数N(2<=N<=100)M(M<=500),表示有N个城市,M条道路接下来M行两个整数,表示相连的两个城市的编号输出描述:N-1行,表示0号城市到其他城市的...原创 2018-03-03 22:23:51 · 856 阅读 · 0 评论 -
判断一棵树是否是完全二叉树
将结点层次遍历,遍历到空结点以后如果队列中还有非空结点,那么不是完全二叉树。原创 2018-03-10 23:47:39 · 365 阅读 · 0 评论 -
二叉排序树的删除
#include "stdafx.h"#include<cstdio>#include<iostream>#include<vector>#include<stack>#include<queue>using namespace std;const int maxn=100;const int inf=0x7ffffff...原创 2018-03-15 15:57:28 · 193 阅读 · 0 评论 -
后序遍历非递归求结点的所有祖先(或求两个节点的最近公共祖先)
#include "stdafx.h"#include<cstdio>#include<iostream>#include<vector>#include<stack>using namespace std;const int maxn=100;struct node{ int data; int tag; node*l,*r;...原创 2018-03-15 14:49:22 · 2508 阅读 · 0 评论 -
PAT Deepest Root
Deepest Root (25)时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)题目描述A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root...原创 2018-02-02 23:08:49 · 182 阅读 · 0 评论