04 2024 档案
摘要:class Solution { public: //用于栈的push 与 pop stack<int> s1; //用于存储最小值min stack<int> s2; //将元素入栈 void push(int value) { s1.push(value); //空元素或者元素较小,则入栈 if
阅读全文
摘要:class Solution { public: //用两个栈实现 队列 栈是先进后出,队列是先进先出 //在队列尾部插入整数 void push(int node) { //入队就正常入栈 stack1.push(node); } //在队列头部删除整数,先进先出 int pop() { //将第
阅读全文
摘要:思路: 因为所有子节点都会指向父节点,所以从给定的那个节点pNode开始找,一直找到根节点root,然后用利用中序遍历,将该树的中序遍历序列存到一个容器中,然后对该容器进行遍历,找到指定节点的下一个节点。 #include <cstddef> class Solution { public: vec
阅读全文
摘要:class Solution { public: //求深度 int deep(TreeNode* root) { if(root == NULL) return 0; //求左右子树的深度 int left = deep(root->left); int right = deep(root->ri
阅读全文
摘要:思路: 既然要找到所有路径上节点和等于目标值的路径个数,就肯定要先找到这样的路径起点。 但是我们不知道起点在哪,而且任意节点都有可能是起点。 以前序遍历二叉树的所有节点,每个节点都可以作为一次起点,即子树的根节点。 class Solution { public: //先序遍历找路径 void Pr
阅读全文
摘要:class Solution { public: //用来判断是否找到节点 bool flag = false; //dfs遍历得到路径,递归遍历,也就是先序遍历根左右 //传入参数:节点,容器,要找的值 void dfs(TreeNode* root, vector<int> & path, in
阅读全文
摘要:/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution
阅读全文
摘要:class Solution { public: //在哪分开,哪里就是公共祖先! //中序遍历二叉树 TreeNode* ans; int lowestCommonAncestor(TreeNode* root, int p, int q) { // write code here int Min
阅读全文
摘要:class Solution { public: //判断该数组是不是某二叉搜索树的后序遍历的结果。 //如果是则返回 true ,否则返回 false //注意传入参数是一个int类型的vector容器 bool VerifySquenceOfBST(vector<int> sequence) {
阅读全文
摘要:/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ #include <cstd
阅读全文
摘要:/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * }
阅读全文
摘要:/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution
阅读全文
摘要:1、相似题 class Solution { public: ListNode* deleteDuplicates(ListNode* head) { //判空 if(head == NULL ) return nullptr; ListNode* p1 = head; ListNode* p2 =
阅读全文
摘要:/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : val(x), next(nullptr) {} * }; */ class Solution { public: /** * 代码中的类名
阅读全文
摘要:/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : val(x), next(nullptr) {} * }; */ class Solution { public: /** * 代码中的类名
阅读全文
摘要:/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ #include <endian.h> class Solution { public: //返回类型
阅读全文
摘要:/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : val(x), next(nullptr) {} * }; */ #include <cstddef> class Solution { p
阅读全文
摘要:/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : val(x), next(nullptr) {} * }; */ #include <cstddef> class Solution { p
阅读全文
摘要:/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : * val(x), next(NULL) { * } * }; */ #include <cstddef> class Solution {
阅读全文
摘要:描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个数字是重复的。也不知道每个数字重复几次。请找出数组中任意一个重复的数字。 例如,如果输入长度为7的数组[2,3,1,0,2,5,3],那么对应的输出是2或者3。存在不合法的输入的话输出-1 数据范围
阅读全文