• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

题目链接:https://leet代码-cn。com/problems/all-elements-in-two-binary搜索树/

个人题解:中序遍历排序

点击查看代码/**

*二叉树节点的定义。

*结构树节点{

* int值

* TreeNode * left

* TreeNode *右

* TreeNode() : val(0),left(nullptr),right(nullptr) {}

* TreeNode(int x) : val(x),left(nullptr),right(nullptr) {}

* TreeNode(int x,TreeNode *left,TreeNode *right) : val(x),left(左),对吧(右){}

* };

*/

类别解决方案{

公共:

矢量美国国家标准(American National Standards的缩写)

void dfs(TreeNode* root)

{

如果(!根)返回;

dfs(左根);

ans。push _ back(root-val);

dfs(根右);

}

矢量getAllElements(TreeNode* root1,TreeNode* root2) {

DFS(根1);

DFS(根2);

sort(ans.begin()、ans。end());

返回美国国家标准(American National Standards的缩写)

}

};

image

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now