
算法刷题
sz66cm
C\C++, Linux shell语言,python
Linux内核驱动开发.
Linux 嵌入式应用开发
Android 多媒体应用开发.
展开
-
LeetCode刷题-1480. 一维数组的动态和
代码】LeetCode刷题-1480. 一维数组的动态和。原创 2022-08-15 21:39:44 · 162 阅读 · 0 评论 -
LeetCode刷题笔记-142.环形链表II
代码】LeetCode刷题笔记-142.环形链表II。原创 2022-08-10 23:09:54 · 287 阅读 · 0 评论 -
LeetCode刷题笔记-876. 链表的中间结点
代码】LeetCode刷题笔记-876. 链表的中间结点。原创 2022-08-04 22:44:30 · 223 阅读 · 0 评论 -
LeetCode刷题笔记-206. 反转链表
代码】LeetCode刷题笔记-206. 反转链表。原创 2022-08-04 00:04:45 · 273 阅读 · 0 评论 -
LeetCode刷题-392. 判断子序列
代码】LeetCode刷题-392. 判断子序列。原创 2022-08-03 01:00:38 · 1434 阅读 · 0 评论 -
LeetCode算法刷题-205. 同构字符串
LeetCode算法刷题-205.同构字符串。原创 2022-08-01 21:02:14 · 314 阅读 · 0 评论 -
LeetCode算法刷题-724. 寻找数组的中心下标
算法刷题原创 2022-07-31 23:56:42 · 233 阅读 · 0 评论 -
LeetCode刷题笔记-112.路径总和
LeetCode刷题 深度优先 路径总和原创 2022-06-11 00:00:39 · 151 阅读 · 0 评论 -
LeetCode刷题笔记-35.搜索插入位置
LeetCode算法刷题记录原创 2022-06-05 14:43:59 · 181 阅读 · 0 评论 -
LeetCode刷题笔记-2.两数相加
LeetCode刷题笔记-2.两数相加思路思路graph LRsubgraph List1l1(())-->l2(())-->l3((...))end原创 2022-05-08 11:10:18 · 253 阅读 · 0 评论 -
LeetCode刷题笔记-39.组合总和
C语言/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free(). */void dfs(int *nums, int num原创 2022-05-06 21:36:28 · 713 阅读 · 0 评论 -
LeetCode刷题笔记-乘积小于k的字数组
LeetCode刷题笔记-乘积小于k的字数组C语言结果C语言结果原创 2022-05-05 19:39:56 · 506 阅读 · 0 评论 -
LeetCode刷题笔记-杨辉三角II
LeetCode刷题笔记-杨辉三角IIC语言zC语言/** * Note: The returned array must be malloced, assume caller calls free(). */int* getRow(int rowIndex, int* returnSize){ int i,j; int len; int rlen; int **dp = NULL; len = rowIndex + 1; dp = calloc(rowIndex原创 2022-05-05 08:55:55 · 686 阅读 · 0 评论 -
LeetCode刷题笔记-34.在排序数组中查找元素的第一个和最后一个位置
C代码/** * Note: The returned array must be malloced, assume caller calls free(). */int* searchRange(int* nums, int numsSize, int target, int* returnSize){ int s, e; int *ret = NULL; ret = calloc(2, sizeof(int)); ret[0] = -1; ret[1] = -1;原创 2022-05-03 15:54:53 · 238 阅读 · 0 评论 -
LeetCode刷题笔记-496.下一个更大元素 I
LeetCode刷题笔记-496.下一个更大元素 IC代码注意点结果C代码/** * Note: The returned array must be malloced, assume caller calls free(). */ struct hmap_st { int key; int value; int index; UT_hash_handle hh;};void push(int *stack, int *top, int val) { (原创 2022-05-02 15:02:12 · 262 阅读 · 0 评论 -
LeetCode刷题笔记-416.分割等和子集
LeetCode刷题笔记-416.分割等和子集C代码注意点结果(待优化)题目C代码bool canPartition(int* nums, int numsSize){ int i,j; bool *dp = NULL; int sum = 0; int hsum = 0; bool ret = false; if(numsSize < 2) { return false; } for (i = 0; i &原创 2022-04-30 17:46:39 · 217 阅读 · 0 评论 -
LeetCode刷题笔记-53.最大子数组和
最大子数组和原创 2022-04-29 13:25:58 · 163 阅读 · 0 评论 -
LeetCode刷题笔记-70.爬楼梯
LeetCode刷题笔记-70.爬楼梯C代码注意点结果题目C代码#define DPSIZE 3int get_index(int i) { return i % DPSIZE;}int climbStairs(int n){ int i; int *dp = NULL; int ret = 0; if (n < 2) { return n; } dp = calloc(DPSIZE, sizeof(int));原创 2022-04-29 13:13:08 · 124 阅读 · 0 评论 -
LeetCode刷题-509.裴波那契数
LeetCode刷题-509.裴波那契数C代码结果注意点题目C代码//动态规划int fib(int n){ int *dp = NULL; int i; int ret = 0; if(n < 2) { return n; } dp = calloc(n+1, sizeof(int)); dp[0] = 0; dp[1] = 1; for (i = 2; i < n+1; i++) {原创 2022-04-29 12:42:02 · 236 阅读 · 0 评论 -
LeetCode刷题笔记-167.两数之和 II - 输入有序数组
LeetCode刷题笔记-167.两数之和 II - 输入有序数组C语言注意点结果题目C语言/** * Note: The returned array must be malloced, assume caller calls free(). */int* twoSum(int* numbers, int numbersSize, int target, int* returnSize){ int s, e; int *ret = NULL; *returnSize =原创 2022-04-25 12:24:45 · 934 阅读 · 0 评论 -
LeetCode刷题笔记-396.旋转函数
LeetCode刷题笔记-396.旋转函数C语言注意点结果题目C语言#define MAX_ONE(a,b) ((a)>(b)?(a):(b))#define INT_MIN 0x80000000int maxRotateFunction(int* nums, int numsSize){ int dp = 0; int max = INT_MIN; int sum = 0; int k; int i; for (i = 0; i < n原创 2022-04-22 13:09:34 · 971 阅读 · 0 评论 -
LeetCode刷题笔记-1.两数之和
LeetCode刷题笔记-1.两数之和C代码注意点结果题目C代码/** * Note: The returned array must be malloced, assume caller calls free(). */struct cmhash_st { int key; int value; UT_hash_han原创 2022-04-21 13:31:33 · 389 阅读 · 0 评论 -
LeetCode刷题笔记-33.搜索旋转排序数组
LeetCode刷题笔记-33.搜索旋转排序数组C代码注意点结果题目C代码int search(int* nums, int numsSize, int target){ int l,h,mid; int i; l = 0; h = numsSize - 1; while(1) { if(l > h) return -1; mid = (l + h) / 2; if(target == nums[l]) re原创 2022-04-21 12:44:56 · 1119 阅读 · 0 评论 -
LeetCode刷题笔记-32.最长有效括号
LeetCode刷题笔记-32.最长有效括号C代码注意点结果题目内存优化版本C代码#define MAX_ONE(a,b) ((a)>(b)?(a):(b))int longestValidParentheses(char * s){ int len; int *dp = NULL; int max = 0; int i; len = strlen(s); if (len < 2) { return 0; }原创 2022-04-18 12:44:41 · 730 阅读 · 0 评论 -
LeetCode刷题笔记-16.最接近的三数之和
LeetCode刷题笔记-16.最接近的三数之和C代码结果注意点C代码#define VALUE(ptr) (*((int *)ptr))#define MIN_ONE(a, b) ((a)>(b)?(b):(a))int comp(const void *a, const void *b) { return VALUE(a) - VALUE(b);}int threeSumClosest(int* nums, int numsSize, int target){ in原创 2022-04-17 16:35:47 · 867 阅读 · 0 评论 -
LeetCode刷题笔记-28.实现strStr()
LeetCode刷题笔记-28.实现strStrC代码注意点prefix table 动态规划法(未完待续)结果题目C代码int *get_prefix_table(char *pp, int psize) { int i = 0; int j; int *dp = NULL; dp = calloc(psize, sizeof(int)); dp[0] = 0; for (i = 1; i < psize; i++) { if (原创 2022-04-17 02:19:45 · 336 阅读 · 0 评论 -
LeetCode刷题笔记-706.设计哈希映射
LeetCode刷题笔记-706.设计哈希映射C代码注意点可以进一步优化的点运行结果C代码#define HMSIZE (1<<20)typedef struct entry_st { int key; int value; struct entry_st *next;} Entry;typedef struct { Entry **data; int cap; int size;} MyHashMap;MyHashMap*原创 2022-04-14 13:07:19 · 341 阅读 · 0 评论 -
LeetCode刷题笔记-27.移除元素
LeetCode刷题笔记-27.移除元素C语言注意点结果题目C语言int removeElement(int* nums, int numsSize, int val){ int i; int cur = 0; for (i = 0; i < numsSize; i++) { if (nums[i] == val) { continue; } nums[cur] = nums[i];原创 2022-04-12 13:04:50 · 977 阅读 · 0 评论 -
LeetCode刷题笔记-26.删除有序数组中的重复项
LeetCode刷题笔记-26.删除有序数组中的重复项C语言注意点结果题目C语言int removeDuplicates(int* nums, int numsSize){ int pre; int i = 0; int cur = 1; if(numsSize < 1) return 0; pre = nums[0]; for (i = 1; i < numsSize; i++) { i原创 2022-04-12 12:54:54 · 724 阅读 · 0 评论 -
LeetCode刷题笔记-剑指 Offer II 024. 反转链表
LeetCode刷题笔记-剑指 Offer II 024. 反转链表C语言注意点结果题目C语言/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* reverseList(struct ListNode* head){ struct ListNode *pre原创 2022-04-10 13:14:56 · 855 阅读 · 0 评论 -
LeetCode刷题笔记-24.两两交换链表的节点
LeetCode刷题笔记-24.两两交换链表的节点C语言注意点结果题目C语言/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* swapPairs(struct ListNode* head){ struct ListNode* dummy = NULL; struc原创 2022-04-08 12:53:36 · 527 阅读 · 0 评论 -
LeetCode刷题笔记-22.括号生成
LeetCode刷题笔记-22.括号生成C语言注意点结果题目C语言/** * Note: The returned array must be malloced, assume caller calls free(). */void bt(char ***ret, int *retsize, int *retcap, char *buf, int l, int r, int n) { if (l > n || r > n) { return; }原创 2022-04-07 13:25:11 · 1045 阅读 · 0 评论 -
LeetCode刷题笔记-21.合并两个有序链表
C代码/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2){ struct ListNode *dummy = NULL; struct ListN原创 2022-04-06 12:28:51 · 575 阅读 · 0 评论 -
LeetCode刷题笔记-8.字符串转整数
LeetCode刷题笔记-8.字符串转整数C代码注意点结果题目C代码enum STATE { START = 0, SIGNED, START_ZERO, NUM, END};enum STATE get_next_state(enum STATE cur, char c) { if (cur == END) { return END; } if (cur == START_ZERO) { switch原创 2022-04-05 23:54:46 · 388 阅读 · 0 评论 -
LeetCode刷题笔记-14.最长公共前缀
LeetCode刷题笔记-14.最长公共前缀C代码C代码char * longestCommonPrefix(char ** strs, int strsSize){ char *ret = NULL; int i, j; int size; size = strlen(strs[0]); ret = strdup(strs[0]); for (i = 1; i < strsSize; i++) { if (size <= 0原创 2022-04-05 13:54:06 · 567 阅读 · 0 评论 -
LeetCode刷题笔记-12.整数转罗马数字
LeetCode刷题笔记-12.整数转罗马数字C代码注意点结果题目C代码int vals[] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};char *rs[] = { [1000] = "M", [900] = "CM", [500] = "D", [400] = "CD", [10原创 2022-04-05 13:30:08 · 802 阅读 · 0 评论 -
LeetCode刷题笔记-13.罗马数字转整数
LeetCode刷题笔记-13.罗马数字转整数C代码思路结果题目C代码#define OFFSET(a) (a -'A')int map[] = { [OFFSET('I')] = 1, [OFFSET('V')] = 5, [OFFSET('X')] = 10, [OFFSET('L')] = 50, [OFFSET('C')] = 100, [OFFSET('D')] = 500, [OFFSET('M')] = 1000};int ro原创 2022-04-05 02:00:42 · 640 阅读 · 0 评论 -
LeetCode刷题笔记-7.整数反转
LeetCode刷题笔记-7.整数反转C代码注意点C代码#define INTMAX (2147483647)#define INXMIN (-2147483648)int reverse(int x){ int ans = 0; while (x != 0) { if (ans > INTMAX/10) return 0; if (ans == INTMAX/10) { if (x % 10 &原创 2022-04-05 01:30:09 · 673 阅读 · 0 评论 -
LeetCode刷题笔记- 845.数组中的最长山脉
LeetCode刷题笔记- 845.数组中的最长山脉C语言思想注意点结果C语言struct mount_st { int up; int down; int is_mountain;};#define MAX_ONE(a,b) ((a)>(b)?(a):(b))int copy(struct mount_st *dst, struct mount_st *src){ memcpy(dst, src, sizeof(struct mount_st));原创 2022-04-03 08:18:29 · 654 阅读 · 0 评论 -
LeetCode刷题笔记- LCP 17.速算机器人
LeetCode刷题笔记- LCP 17.速算机器人C代码注意点结果题目C代码int calculate(char* s){ int x = 1, y = 0; while (s != NULL && *s != '\0') { if (*s == 'A') { x = 2 * x + y; } else { y = 2 * y + x; } s++;原创 2022-04-02 23:33:55 · 120 阅读 · 0 评论