码迷,mamicode.com
首页 >  
搜索关键字:treenode    ( 1958个结果
Leetcode101.对称二叉树
题目 1 class Solution { 2 public: 3 4 bool isSymmetric(TreeNode* root) { 5 return check(root,root); 6 } 7 bool check(TreeNode* p,TreeNode* q) { 8 if(!p ...
分类:其他好文   时间:2021-01-05 11:37:37    阅读次数:0
Leetcode100.相同的树
题目描述 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode() : val(0), ...
分类:其他好文   时间:2021-01-05 11:28:10    阅读次数:0
剑指 Offer 28. 对称的二叉树
剑指 Offer 28. 对称的二叉树 class Solution { public boolean isSymmetric(TreeNode root) { if(root == null) return true; return Just(root.left,root.right); } pu ...
分类:其他好文   时间:2021-01-05 11:27:06    阅读次数:0
迭代法 二叉树前序、中序、后序 遍历
前序 class Solution { public: vector<int> preorderTraversal(TreeNode* root) { vector<int> res; if (root == nullptr) { return res; } stack<TreeNode*> stk ...
分类:其他好文   时间:2021-01-01 12:36:16    阅读次数:0
LeetCode109. 有序链表转换二叉搜索树
思路:和108题类似,链表需要通过双指针寻找中间节点。 class Solution { public TreeNode sortedListToBST(ListNode head) { if (head == null) return null; if (head.next == null) re ...
分类:其他好文   时间:2020-12-30 11:35:50    阅读次数:0
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ ...
分类:其他好文   时间:2020-12-23 11:52:45    阅读次数:0
二叉树的递归遍历框架:
/二叉树的遍历框架/ void traverse(TreeNode root) { //前序遍历:先访问根节点,再前序访问左子树,再访问右子树 traverse(root->left); //中序遍历:先中序访问左子树,再访问根节点,再访问右子树 traverse(root->right); //后 ...
分类:其他好文   时间:2020-12-17 13:11:47    阅读次数:9
二叉树各种(层序)遍历?
深度广度遍历// 根据前序和中序重建二叉树/* function TreeNode(x) { this.val = x; this.left = null; this.right = null;} */function reConstructBinaryTree(pre, vin){ var res ...
分类:其他好文   时间:2020-12-09 12:27:49    阅读次数:10
LC 222. Count Complete Tree Nodes (二分查找)
link /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NUL ...
分类:其他好文   时间:2020-11-27 11:14:59    阅读次数:5
102. 二叉树的层序遍历
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * Return an arr ...
分类:其他好文   时间:2020-11-26 14:41:52    阅读次数:8
1958条   上一页 1 ... 4 5 6 7 8 ... 196 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!