随笔分类 - 数据结构 / 树
摘要:public boolean isSymmetric(TreeNode root) { if(root == null){ return true; } return judge(root.left,root.right); } //左节点的left = 右节点的right 左节点的right =
阅读全文
摘要:public TreeNode mirrorTree(TreeNode root) { if(root == null){ return null; } TreeNode left=mirrorTree(root.left); TreeNode right=mirrorTree(root.right
阅读全文
摘要:/遍历A树,用每个节点开始与B进行比较 public boolean isSubStructure(TreeNode A, TreeNode B) { return (A != null && B != null) && (recur(A, B) || isSubStructure(A.left,
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), r
阅读全文
摘要:TreeNode* mergeTrees(TreeNode* root1, TreeNode* root2) { if(root1==nullptr){ return root2; }else if(root2==nullptr){ return root1; } TreeNode* root=ne
阅读全文
摘要:Node* connect(Node* root) { if(root==NULL){ return root; } queue<Node*> q; q.push(root); while(!q.empty()){ int size=q.size(); for(int i=0;i<size;i++)
阅读全文