This commit is contained in:
2025-09-15 21:12:04 +08:00
commit 3f58f483ff
144 changed files with 5298 additions and 0 deletions

19
24/02/235.h Normal file
View File

@@ -0,0 +1,19 @@
//
// Created by 李洋 on 2024/2/25.
//
#ifndef LEETCODE_C_235_H
#define LEETCODE_C_235_H
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
};
struct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) {
}
#endif //LEETCODE_C_235_H

82
24/02/429.h Normal file
View File

@@ -0,0 +1,82 @@
//
// Created by 李洋 on 2024/2/17.
//
#ifndef LEETCODE_C_429_H
#define LEETCODE_C_429_H
#include "stdlib.h"
struct Node {
int val;
int numChildren;
struct Node **children;
};
struct linkedNode {
int val;
struct linkedNode *next;
};
struct queue {
struct linkedNode *head;
struct linkedNode *tail;
int size;
};
void push(struct queue Q, int val) {
struct linkedNode *temp = (struct linkedNode *) malloc(sizeof(struct linkedNode));
Q.size++;
if (Q.size == 0) {
temp->val = val;
Q.head = temp;
Q.tail = temp;
return;
}
Q.tail->next = temp;
Q.tail = temp;
}
int pop(struct queue Q) {
int top = Q.head->val;
struct linkedNode *temp = Q.head;
Q.head = temp->next;
free(temp);
Q.size--;
return top;
}
int top(struct queue Q) {
return Q.head->val;
}
int **levelOrder(struct Node *root, int *returnSize, int **returnColumnSizes) {
int ** ans = (int **)malloc(sizeof(int *) * 1000);
*returnColumnSizes = (int *)malloc(sizeof(int) * 1000);
if (!root) {
*returnSize = 0;
return ans;
}
struct Node ** queue = (struct Node **)malloc(sizeof(struct Node *) * 10000);
int head = 0, tail = 0;
int level = 0;
queue[tail++] = root;
while (head != tail) {
int cnt = tail - head;
ans[level] = (int *)malloc(sizeof(int) * cnt);
for (int i = 0; i < cnt; ++i) {
struct Node * cur = queue[head++];
ans[level][i] = cur->val;
for (int j = 0; j < cur->numChildren; j++) {
queue[tail++] = cur->children[j];
}
}
(*returnColumnSizes)[level++] = cnt;
}
*returnSize = level;
free(queue);
return ans;
}
#endif //LEETCODE_C_429_H

41
24/02/590.h Normal file
View File

@@ -0,0 +1,41 @@
//
// Created by 李洋 on 2024/2/19.
//
#ifndef LEETCODE_C_590_H
#define LEETCODE_C_590_H
#include <stdlib.h>
struct Node {
int val;
int numChildren;
struct Node **children;
};
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
#define MAX_NODE_SIZE 10000
void helper(const struct Node* root, int* res, int* pos) {
if (NULL == root) {
return;
}
for (int i = 0; i < root->numChildren; i++) {
helper(root->children[i], res, pos);
}
res[(*pos)++] = root->val;
}
int* postorder(struct Node* root, int* returnSize) {
int * res = (int *)malloc(sizeof(int) * MAX_NODE_SIZE);
int pos = 0;
helper(root, res, &pos);
*returnSize = pos;
return res;
}
#endif //LEETCODE_C_590_H