题外话:考试的时候花了一个小时做了27分,由于Siblings这个单词不知道意思,所以剩下的3分就没去纠结了,后来发现单词是兄弟的意思,气哭~~ 这道题的麻烦之处在于如何从一个字符串中去找数字.先首先我们需要整行读取(包括空格),这个我自己写另一个函数,挺好用的: string mygets() { ]; fgets(str,sizeof(str),stdin); int len = strlen(str); ]==] = '\0'; return str; } 用的时候只要 string st…
这是悦乐书的第285次更新,第302篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第153题(顺位题号是671).给定非空的特殊二叉树,其由具有非负值的节点组成,其中该树中的每个节点具有恰好两个或零个子节点. 如果节点具有两个子节点,则该节点的值是其两个子节点中的较小值.给定这样的二叉树,您需要输出由整个树中所有节点的值组成的集合中的第二个最小值.如果不存在这样的第二个最小值,则输出-1.例如: 2 / \ 2 5 / \ 5 7 输出:5 2 / \ 2 2 输出…
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 解题: 递归就行:根节点为空,返回0:一个子树根节点为空,另一个子树根节点不为空,就返回根节点不为空的子树高度:否则返回两个子树中高度大者加一. 代码: /** * Definit…
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 题解:递归解决,用私有变量minDep保存最小的深度,每当遍历到叶节点的时候就看是否需要更新. 代码如下: /** * Definition for binary tree * p…
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 题解:递归,树的高度 = max(左子树高度,右子树高度)+1: 代码如下: /** * Definition for binary tree * public class Tre…
7-4 Cartesian Tree (30分)   A Cartesian tree is a binary tree constructed from a sequence of distinct numbers. The tree is heap-ordered, and an inorder traversal returns the original sequence. For example, given the sequence { 8, 15, 3, 4, 1, 5, 12, 1…
1119 Pre- and Post-order Traversals (30 分) Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences, or preorder and inorder travers…
1095 Cars on Campus (30 分) Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at…
PAT(甲级)2017年春季考试 A.Raffle for Weibo Followers #include<bits/stdc++.h> using namespace std; int m,n,s; vector<string> person; set<string> se; vector<string> ans; int main(){ cin>>m>>n>>s; for(int i=1;i<=m;i++){…
// 此博文为迁移而来,写于2015年7月22日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w72i.html 1.总结        向总表示今天的题目简单些,恩我觉得我又单纯了.今天的分数略低啊,第三题的动规只有10分,第一题的暴力也TLE了一堆,最后就剩下个150分了.   2.题解        T1 坐船问题(TAG:结论题)          简直就是一道结论题啊!这道题不存在什么算法.最开始想到的是二…