分类: leetcode

14 篇文章

LC160 相交链表
typedef struct ListNode listNode; struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) { listNode *a = headA, *b = headB; while (a != b && (a->…
LC142 环形链表 II
typedef struct listNode { int val; struct listNode *next; } listNode; struct ListNode *detectCycle(struct ListNode *head) { if (head == NULL || head->next == NULL || head->nex…
LC141 环形链表
typedef struct listNode { int val; struct listNode *next; } listNode; bool hasCycle(struct ListNode *head) { if (head == NULL) return false; listNode *fast = head->next, *slow…
LC707 设计链表
typedef struct MyLinkedList { int val; struct MyLinkedList *next; } MyLinkedList; MyLinkedList* myLinkedListCreate() { MyLinkedList *newList = malloc(sizeof(MyLinkedList)); ne…
LC23 合并K个升序链表
struct ListNode { int val; struct ListNode *next; }; struct ListNode *mergeTwoList(struct ListNode *list1, struct ListNode *list2) { struct ListNode *newList; struct ListNode …
LC84 柱状图中最大的矩形
int largestRectangleArea(int* heights, int heightsSize){ int left[100000], right[100000], stack[100000]; int top = -1, max = 0; for (int i = 0; i < heightsSize; i++) { while (…
LC503 下一个更大元素II
int* nextGreaterElements(int* nums, int numsSize, int* returnSize){ int *ret = malloc(sizeof(int) * numsSize); int stack[numsSize]; int top = -1; for (int i = 0; i < numsSize …
LC85 最大矩形
int max_value(int *line, int len) { int max = 0, top = -1; int stack[len], right[len], left[len]; for (int i = 0; i < len; i++) { while (top >= 0 && line[i] < line[stack[top]]…
LC42 接雨水
//单调栈解法 int trap(int* height, int heightSize){ int stack[heightSize]; int area = 0, top = -1; for (int i = 0; i < heightSize; i++) { while ( top > 0 && height[i] > height[stac…
HJ26 字符串排序
#include int main() { char str[1001], ret[1001]; scanf("%s", str); int index = 0; for (char i = 'A'; i = 'a' && str[k] = 'A' && str[k]