![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二叉树
limboWang
这个作者很懒,什么都没留下…
展开
-
PAT甲级-1151 LCA in a Binary Tree (30 分)
题目:1151 LCA in a Binary Tree (30 分) 分析:一般二叉树的LCA #include <iostream> #include<cstring> #include<vector> #include<stdio.h> #include<queue> #include<math.h> #include<stack> #include<algorithm> #include<map.原创 2021-03-05 11:44:16 · 76 阅读 · 0 评论 -
PAT甲级-1143 Lowest Common Ancestor (30 分)
题目:1143 Lowest Common Ancestor (30 分) 分析:第一次写的时候先建树,然后在树中向父母进行查找判断,很麻烦。看了题解之后发现可以利用二叉树的特性来解决。 #include<iostream> #include<algorithm> #include<math.h> #include<cstring> #include<queue> #include<stack> #include<map>.原创 2021-03-05 10:42:08 · 92 阅读 · 1 评论 -
PAT甲级-1119 Pre- and Post-order Traversals (30 分)
题目:1119 Pre- and Post-order Traversals (30 分) 分析:二叉树,前序和后序判断是否唯一,输出中序 #include <iostream> #include <vector> #include <string.h> #include<stdio.h> using namespace std; typedef struct node{ int left = -1; int right = -1; }; .原创 2021-02-21 12:46:55 · 84 阅读 · 0 评论 -
PAT甲级-1086 Tree Traversals Again (25 分)
题目:1086 Tree Traversals Again (25 分) 分析:根据二叉树的前序和中序建树,输出后序。 #include <iostream> #include<cstring> #include<vector> #include<stdio.h> #include<queue> #include<math.h> #include<stack> #include<algorithm> #inc.原创 2021-02-06 11:59:32 · 61 阅读 · 1 评论 -
PAT甲级-1066 Root of AVL Tree (25分)
题目:1066 Root of AVL Tree (25分) 分析:AVL树的建立,理解了AVL的概念之后就好下手。 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <stack> #include <set> #include <map> #include <math.h> #incl.原创 2021-01-29 12:04:51 · 57 阅读 · 0 评论 -
PAT甲级-1053 Path of Equal Weight (30分)
题目:1053 Path of Equal Weight (30分) 分析:排序题,这里输出的时候直接sort,没有写cmp函数,则从尾部开始输出,或者也可以在输入的时候对每个节点的孩子进行sort(很多博客都是这样写的,代码都一样,但还是要根据自己的思路来比较好) #include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <stack&.原创 2021-01-24 15:03:04 · 118 阅读 · 0 评论 -
PAT甲级-1043 Is It a Binary Search Tree (25分)
题目:1043 Is It a Binary Search Tree (25分) 分析:二叉搜索树的判断(BST),本题要求判断输入序列是不是二叉搜索树的前序或者是该二叉搜索树的镜像的前序,代码有点长,但易懂 #include <iostream> #include<cstring> #include<vector> #include<stdio.h> #include<queue> #include<math.h> #includ.原创 2021-01-23 13:34:20 · 79 阅读 · 0 评论 -
PAT甲级-1020 Tree Traversals (25分)
1020 Tree Traversals (25分)题目:[https://pintia.cn/problem-sets/994805342720868352/problems/994805485033603072]()分析:给二叉树的中序和后序,建立二叉树后输出层序遍历即可 题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805485033603072 分析:给二叉树的中序和后序,建立二叉树后输出层序遍历即可 #includ原创 2021-01-19 12:36:49 · 65 阅读 · 0 评论 -
PAT甲级-1021 Deepest Root(25分)
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805482919673856 分析:找出以某个节点为根时,最深的根,这题可能会超时要用vector来表示二维数组 疑问:代码一是第二次写的超时了,代码二是第一次写的AC了,找不出超时代码的问题,难受o(╥﹏╥)o 代码一:超时了 #include <iostream> #include<cstring> #include<vector> .原创 2021-01-19 15:02:48 · 217 阅读 · 0 评论