题目 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
题目描述 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. 对称的二叉树 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
思路:和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
/** * 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
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
/** * 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