【LeetCode刷题日记】树类题目常见题型_leetcode 树 题目(1)

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Golang全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注go)
img

正文

在这里插入图片描述
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-t649bQ1H-1631410485856)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906222707569.png#pic_center)]
)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WJP8QBir-1631410165737)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906223024841.png


104. 二叉树的最大深度

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hokROzkn-1631410165737)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906225439631.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-c6vkvJPE-1631410165738)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906230105322.png)]

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode *root) {
if (root == NULL) return 0;
return fmax(maxDepth(root->left), maxDepth(root->right)) + 1;
}


/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* 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(left), right(right) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode* root) {
if (root == nullptr) return 0;
return max(maxDepth(root->left), maxDepth(root->right)) + 1;
}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-K6grKsYv-1631410165738)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906230159673.png)]

struct QueNode {
struct TreeNode *p;
struct QueNode *next;
};

void init(struct QueNode **p, struct TreeNode *t) {
(*p) = (struct QueNode *)malloc(sizeof(struct QueNode));
(*p)->p = t;
(*p)->next = NULL;
}

int maxDepth(struct TreeNode *root) {
if (root == NULL) return 0;
struct QueNode *left, *right;
init(&left, root);
right = left;
int ans = 0, sz = 1, tmp = 0;
while (left != NULL) {
tmp = 0;
while (sz > 0) {
if (left->p->left != NULL) {
init(&right->next, left->p->left);
right = right->next;
tmp++;
}
if (left->p->right != NULL) {
init(&right->next, left->p->right);
right = right->next;
tmp++;
}
left = left->next;
sz–;
}
sz += tmp;
ans++;
}
return ans;
}


class Solution {
public:
int maxDepth(TreeNode* root) {
if (root == nullptr) return 0;
queue<TreeNode*> Q;
Q.push(root);
int ans = 0;
while (!Q.empty()) {
int sz = Q.size();
while (sz > 0) {
TreeNode* node = Q.front();Q.pop();
if (node->left) Q.push(node->left);
if (node->right) Q.push(node->right);
sz -= 1;
}
ans += 1;
}
return ans;
}
};

102. 二叉树的层序遍历

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FSQWBJz6-1631410165739)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906230630256.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hVrPvVav-1631410165739)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906230809581.png)]

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* 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(left), right(right) {}
* };
*/
class Solution {
public:
vector<vector> levelOrder(TreeNode* root) {
vector <vector > ret;
if (!root) {
return ret;
}

queue <TreeNode*> q;
q.push(root);
while (!q.empty()) {
int currentLevelSize = q.size();
ret.push_back(vector ());
for (int i = 1; i <= currentLevelSize; ++i) {
auto node = q.front(); q.pop();
ret.back().push_back(node->val);
if (node->left) q.push(node->left);
if (node->right) q.push(node->right);
}
}

return ret;
}
};

94. 二叉树的中序遍历

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-haY1LbiS-1631410165739)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906231012868.png)]

image-20210906231031428

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eKamUhz6-1631410165740)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906231108467.png)]

void inorder(struct TreeNode* root, int* res, int* resSize) {
if (!root) {
return;
}
inorder(root->left, res, resSize);
res[(*resSize)++] = root->val;
inorder(root->right, res, resSize);
}

int* inorderTraversal(struct TreeNode* root, int* returnSize) {
int* res = malloc(sizeof(int) * 501);
*returnSize = 0;
inorder(root, res, returnSize);
return res;
}


class Solution {
public:
void inorder(TreeNode* root, vector& res) {
if (!root) {
return;
}
inorder(root->left, res);
res.push_back(root->val);
inorder(root->right, res);
}
vector inorderTraversal(TreeNode* root) {
vector res;
inorder(root, res);
return res;
}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1ykLuVUp-1631410165741)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906231203588.png)]

int* inorderTraversal(struct TreeNode* root, int* returnSize) {
*returnSize = 0;
int* res = malloc(sizeof(int) * 501);
struct TreeNode** stk = malloc(sizeof(struct TreeNode*) * 501);
int top = 0;
while (root != NULL || top > 0) {
while (root != NULL) {
stk[top++] = root;
root = root->left;
}
root = stk[–top];
res[(*returnSize)++] = root->val;
root = root->right;
}
return res;
}


Solution {
public:
vector inorderTraversal(TreeNode* root) {
vector res;
stack<TreeNode*> stk;
while (root != nullptr || !stk.empty()) {
while (root != nullptr) {
stk.push(root);
root = root->left;
}
root = stk.top();
stk.pop();
res.push_back(root->val);
root = root->right;
}
return res;
}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dOsyM3uB-1631410165741)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906231316031.png)]

int* inorderTraversal(struct TreeNode* root, int* returnSize) {
int* res = malloc(sizeof(int) * 501);
*returnSize = 0;
struct TreeNode* predecessor = NULL;

while (root != NULL) {
if (root->left != NULL) {
// predecessor 节点就是当前 root 节点向左走一步,然后一直向右走至无法走为止
predecessor = root->left;
while (predecessor->right != NULL && predecessor->right != root) {
predecessor = predecessor->right;
}

// 让 predecessor 的右指针指向 root,继续遍历左子树
if (predecessor->right == NULL) {
predecessor->right = root;
root = root->left;
}
// 说明左子树已经访问完了,我们需要断开链接
else {
res[(*returnSize)++] = root->val;
predecessor->right = NULL;
root = root->right;
}
}
// 如果没有左孩子,则直接访问右孩子
else {
res[(*returnSize)++] = root->val;
root = root->right;
}
}
return res;
}


class Solution {
public:
vector inorderTraversal(TreeNode* root) {
vector res;
TreeNode *predecessor = nullptr;

while (root != nullptr) {
if (root->left != nullptr) {
// predecessor 节点就是当前 root 节点向左走一步,然后一直向右走至无法走为止
predecessor = root->left;
while (predecessor->right != nullptr && predecessor->right != root) {
predecessor = predecessor->right;
}

// 让 predecessor 的右指针指向 root,继续遍历左子树
if (predecessor->right == nullptr) {
predecessor->right = root;
root = root->left;
}
// 说明左子树已经访问完了,我们需要断开链接
else {
res.push_back(root->val);
predecessor->right = nullptr;
root = root->right;
}
}
// 如果没有左孩子,则直接访问右孩子
else {
res.push_back(root->val);
root = root->right;
}
}
return res;
}
};

101. 对称二叉树

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DDaijCXA-1631410165741)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906231723650.png)]

image-20210906231758325

class Solution {
public:
bool check(TreeNode *p, TreeNode *q) {
if (!p && !q) return true;
if (!p || !q) return false;
return p->val == q->val && check(p->left, q->right) && check(p->right, q->left);
}

bool isSymmetric(TreeNode* root) {
return check(root, root);
}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TJOn4n2k-1631410165742)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906231838027.png)]

class Solution {
public:
bool check(TreeNode *u, TreeNode *v) {
queue <TreeNode*> q;
q.push(u); q.push(v);
while (!q.empty()) {
u = q.front(); q.pop();
v = q.front(); q.pop();
if (!u && !v) continue;
if ((!u || !v) || (u->val != v->val)) return false;

q.push(u->left);
q.push(v->right);

q.push(u->right);
q.push(v->left);
}
return true;
}

bool isSymmetric(TreeNode* root) {
return check(root, root);
}
};

98. 验证二叉搜索树

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XEZkgoUx-1631410165742)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906232046142.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VP8vQGV3-1631410165743)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906232733702.png)]

class Solution {
public:
bool helper(TreeNode* root, long long lower, long long upper) {
if (root == nullptr) {
return true;
}
if (root -> val <= lower || root -> val >= upper) {
return false;
}
return helper(root -> left, lower, root -> val) && helper(root -> right, root -> val, upper);
}
bool isValidBST(TreeNode* root) {
return helper(root, LONG_MIN, LONG_MAX);
}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YXztDcbC-1631410165743)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906232758657.png)]

class Solution {
public:
bool isValidBST(TreeNode* root) {
stack<TreeNode*> stack;
long long inorder = (long long)INT_MIN - 1;

while (!stack.empty() || root != nullptr) {
while (root != nullptr) {
stack.push(root);
root = root -> left;
}
root = stack.top();
stack.pop();
// 如果中序遍历得到的节点的值小于等于前一个 inorder,说明不是二叉搜索树
if (root -> val <= inorder) {
return false;
}
inorder = root -> val;
root = root -> right;
}
return true;
}
};

100. 相同的树

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9x97yxnb-1631410165743)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906232905376.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tpraHkvi-1631410165744)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906232942970.png)]

bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
if (p == NULL && q == NULL) {
return true;
} else if (p == NULL || q == NULL) {
return false;
} else if (p->val != q->val) {
return false;
} else {
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
}

class Solution {
public:
bool isSameTree(TreeNode* p, TreeNode* q) {
if (p == nullptr && q == nullptr) {
return true;
} else if (p == nullptr || q == nullptr) {
return false;
} else if (p->val != q->val) {
return false;
} else {
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7oaAoo5M-1631410165744)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233029546.png)]

bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
if (p == NULL && q == NULL) {
return true;
} else if (p == NULL || q == NULL) {
return false;
}
struct TreeNode** que1 = (struct TreeNode**)malloc(sizeof(struct TreeNode*));
struct TreeNode** que2 = (struct TreeNode**)malloc(sizeof(struct TreeNode*));
int queleft1 = 0, queright1 = 0;
int queleft2 = 0, queright2 = 0;
que1[queright1++] = p;
que2[queright2++] = q;
while (queleft1 < queright1 && queleft2 < queright2) {
struct TreeNode* node1 = que1[queleft1++];
struct TreeNode* node2 = que2[queleft2++];
if (node1->val != node2->val) {
return false;
}
struct TreeNode* left1 = node1->left;
struct TreeNode* right1 = node1->right;
struct TreeNode* left2 = node2->left;
struct TreeNode* right2 = node2->right;
if ((left1 == NULL) ^ (left2 == NULL)) {
return false;
}
if ((right1 == NULL) ^ (right2 == NULL)) {
return false;
}
if (left1 != NULL) {
queright1++;
que1 = realloc(que1, sizeof(struct TreeNode*) * queright1);
que1[queright1 - 1] = left1;
}
if (right1 != NULL) {
queright1++;
que1 = realloc(que1, sizeof(struct TreeNode*) * queright1);
que1[queright1 - 1] = right1;
}
if (left2 != NULL) {
queright2++;
que2 = realloc(que2, sizeof(struct TreeNode*) * queright2);
que2[queright2 - 1] = left2;
}
if (right2 != NULL) {
queright2++;
que2 = realloc(que2, sizeof(struct TreeNode*) * queright2);
que2[queright2 - 1] = right2;
}
}
return queleft1 == queright1 && queleft2 == queright2;
}


class Solution {
public:
bool isSameTree(TreeNode* p, TreeNode* q) {
if (p == nullptr && q == nullptr) {
return true;
} else if (p == nullptr || q == nullptr) {
return false;
}
queue <TreeNode*> queue1, queue2;
queue1.push§;
queue2.push(q);
while (!queue1.empty() && !queue2.empty()) {
auto node1 = queue1.front();
queue1.pop();
auto node2 = queue2.front();
queue2.pop();
if (node1->val != node2->val) {
return false;
}
auto left1 = node1->left, right1 = node1->right, left2 = node2->left, right2 = node2->right;
if ((left1 == nullptr) ^ (left2 == nullptr)) {
return false;
}
if ((right1 == nullptr) ^ (right2 == nullptr)) {
return false;
}
if (left1 != nullptr) {
queue1.push(left1);
}
if (right1 != nullptr) {
queue1.push(right1);
}
if (left2 != nullptr) {
queue2.push(left2);
}
if (right2 != nullptr) {
queue2.push(right2);
}
}
return queue1.empty() && queue2.empty();
}
};

226. 翻转二叉树

image-20210906233146066

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eHkkuHEY-1631410165745)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233211449.png)]

struct TreeNode* invertTree(struct TreeNode* root) {
if (root == NULL) {
return NULL;
}
struct TreeNode* left = invertTree(root->left);
struct TreeNode* right = invertTree(root->right);
root->left = right;
root->right = left;
return root;
}


class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
if (root == nullptr) {
return nullptr;
}
TreeNode* left = invertTree(root->left);
TreeNode* right = invertTree(root->right);
root->left = right;
root->right = left;
return root;
}
};

144. 二叉树的前序遍历

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IVY2Xsww-1631410165745)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233405175.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VqSyQqMO-1631410165746)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233442557.png)]

void preorder(struct TreeNode* root, int* res, int* resSize) {
if (root == NULL) {
return;
}
res[(*resSize)++] = root->val;
preorder(root->left, res, resSize);
preorder(root->right, res, resSize);
}

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
int* res = malloc(sizeof(int) * 2000);
*returnSize = 0;
preorder(root, res, returnSize);
return res;
}


class Solution {
public:
void preorder(TreeNode *root, vector &res) {
if (root == nullptr) {
return;
}
res.push_back(root->val);
preorder(root->left, res);
preorder(root->right, res);
}

vector preorderTraversal(TreeNode *root) {
vector res;
preorder(root, res);
return res;
}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4Ui2W7OE-1631410165746)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233539153.png)]

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
int* res = malloc(sizeof(int) * 2000);
*returnSize = 0;
if (root == NULL) {
return res;
}

struct TreeNode* stk[2000];
struct TreeNode* node = root;
int stk_top = 0;
while (stk_top > 0 || node != NULL) {
while (node != NULL) {
res[(*returnSize)++] = node->val;
stk[stk_top++] = node;
node = node->left;
}
node = stk[–stk_top];
node = node->right;
}
return res;
}


class Solution {
public:
vector preorderTraversal(TreeNode* root) {
vector res;
if (root == nullptr) {
return res;
}

stack<TreeNode*> stk;
TreeNode* node = root;
while (!stk.empty() || node != nullptr) {
while (node != nullptr) {
res.emplace_back(node->val);
stk.emplace(node);
node = node->left;
}
node = stk.top();
stk.pop();
node = node->right;
}
return res;
}
};

111. 二叉树的最小深度

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ccT0q5XO-1631410165747)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233645598.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-x0EskIlp-1631410165747)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233711706.png)]

int minDepth(struct TreeNode *root) {
if (root == NULL) {
return 0;
}

if (root->left == NULL && root->right == NULL) {
return 1;
}

int min_depth = INT_MAX;
if (root->left != NULL) {
min_depth = fmin(minDepth(root->left), min_depth);
}
if (root->right != NULL) {
min_depth = fmin(minDepth(root->right), min_depth);
}

return min_depth + 1;
}


class Solution {
public:
int minDepth(TreeNode *root) {
if (root == nullptr) {
return 0;
}

if (root->left == nullptr && root->right == nullptr) {
return 1;
}

int min_depth = INT_MAX;
if (root->left != nullptr) {
min_depth = min(minDepth(root->left), min_depth);
}
if (root->right != nullptr) {
min_depth = min(minDepth(root->right), min_depth);
}

return min_depth + 1;
}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ydP328lE-1631410165748)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233802403.png)]

typedef struct {
int val;
struct TreeNode *node;
struct queNode *next;
} queNode;

void init(queNode **p, int val, struct TreeNode *node) {
(*p) = (queNode *)malloc(sizeof(queNode));
(*p)->val = val;
(*p)->node = node;
(*p)->next = NULL;
}

int minDepth(struct TreeNode *root) {
if (root == NULL) {
return 0;
}

queNode *queLeft, *queRight;
init(&queLeft, 1, root);
queRight = queLeft;
while (queLeft != NULL) {
struct TreeNode *node = queLeft->node;
int depth = queLeft->val;
if (node->left == NULL && node->right == NULL) {
return depth;
}
if (node->left != NULL) {
init(&queRight->next, depth + 1, node->left);
queRight = queRight->next;
}
if (node->right != NULL) {
init(&queRight->next, depth + 1, node->right);
queRight = queRight->next;
}
queLeft = queLeft->next;
}
return false;
}


class Solution {
public:
int minDepth(TreeNode *root) {
if (root == nullptr) {
return 0;
}

queue<pair<TreeNode *, int> > que;
que.emplace(root, 1);
while (!que.empty()) {
TreeNode *node = que.front().first;
int depth = que.front().second;
que.pop();
if (node->left == nullptr && node->right == nullptr) {
return depth;
}
if (node->left != nullptr) {
que.emplace(node->left, depth + 1);
}
if (node->right != nullptr) {
que.emplace(node->right, depth + 1);
}
}

return 0;
}
};

112. 路径总和

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-00hgieFP-1631410165748)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906233938807.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-H8hDaV3s-1631410165748)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906234012608.png)]

typedef struct queNode {
int val;
struct TreeNode *node;
struct queNode *next;
} queNode;

void init(struct queNode **p, int val, struct TreeNode *node) {
(*p) = (struct queNode *)malloc(sizeof(struct queNode));
(*p)->val = val;
(*p)->node = node;
(*p)->next = NULL;
}

bool hasPathSum(struct TreeNode *root, int sum) {
if (root == NULL) {
return false;
}
struct queNode *queLeft, *queRight;
init(&queLeft, root->val, root);
queRight = queLeft;
while (queLeft != NULL) {

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Go)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
06233938807.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-H8hDaV3s-1631410165748)(https://raw.githubusercontent.com/xkyvvv/blogpic/main/pic1/image-20210906234012608.png)]

typedef struct queNode {
int val;
struct TreeNode *node;
struct queNode *next;
} queNode;

void init(struct queNode **p, int val, struct TreeNode *node) {
(*p) = (struct queNode *)malloc(sizeof(struct queNode));
(*p)->val = val;
(*p)->node = node;
(*p)->next = NULL;
}

bool hasPathSum(struct TreeNode *root, int sum) {
if (root == NULL) {
return false;
}
struct queNode *queLeft, *queRight;
init(&queLeft, root->val, root);
queRight = queLeft;
while (queLeft != NULL) {

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Go)
[外链图片转存中…(img-xoegFzqE-1713437260657)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 20
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用\[1\]和引用\[2\]的内容,推荐的LeetCode顺序是按照题目,优先选择、链表、二分查找、DFS、BFS、动态规划等常见题目。可以先做2~4道简单,然后再做中等难度的题目。在选择题目时,可以优先选择题目序号小、点赞多、提交成功率高的题目,这样可以从简单入手,节省时间。同时,LeetCode每道题目都有“模拟面试”功能,可以给自己设定时间限制,如果做不出来可以看答案,然后记住思路后再自己尝试一遍。每种类题目做完10+道后,可以总结规律。 根据引用\[3\]的内容,题目可以按照不同的分类进行,比如数组与贪心算法、子数组与贪心算法、子序列与贪心算法、数字与贪心、单调栈法、双指针法等。可以根据自己的兴趣和需求选择相应的题目进行。 综上所述,LeetCode顺序可以按照题目或者题目分类进行选择。 #### 引用[.reference_title] - *1* [LeetCode 顺序,按标签分类,科学!](https://blog.csdn.net/fengyuyeguirenenen/article/details/125099023)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [leetcode 指南 & 顺序](https://blog.csdn.net/qijingpei/article/details/125561071)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [leetcode-顺序推荐](https://blog.csdn.net/weixin_38087674/article/details/114107841)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值