leetcode
poinsettia
这个作者很懒,什么都没留下…
展开
-
121.leetcode.买卖股票的最佳时机
利用动态规划筛选出来的题目,不过好像也算不上动态规划。 int maxProfit(int* prices, int pricesSize) { int ans = 0; if (pricesSize <= 1) { return ans; } int curMin = prices[0]; for (int i = 1; i < pricesSize; i++) { ans = ans > (prices[原创 2020-12-03 21:36:04 · 74 阅读 · 0 评论 -
2.leetcode.两数相加
这道题直接用暴力法解即可,对于用C语言来实现的筒子来说,最重要的是有耐心。 struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) { struct ListNode* head = NULL; struct ListNode* curNode = NULL; struct ListNode* newNode = NULL; int jinWei = 0; while原创 2020-12-03 21:09:30 · 80 阅读 · 0 评论 -
38.leetcode.外观数列 暴力双指针
void sayPre(char *pre, char *cur) { int l = 0; int r = 0; int len = 0; do { r++; if (pre[r] != pre[l]) { cur[len] = r - l + '0'; cur[len + 1] = pre[l]; cur[len + 2] = '\0'; len原创 2020-11-24 11:40:10 · 122 阅读 · 0 评论 -
26. 删除排序数组中的重复项---双指针
int removeDuplicates(int* nums, int numsSize) { if (nums == NULL || numsSize == 0) { return 0; } int p = 0; for (int q = 1; q < numsSize; q++) { if (nums[q] != nums[p]) { nums[p + 1] = nums[q]; p++原创 2020-11-23 22:15:28 · 76 阅读 · 0 评论 -
leetcode.14. 最长公共前缀
char * longestCommonPrefix(char ** strs, int strsSize) { char *ans = (char *)malloc(sizeof(char)); ans[0] = 0; if (strs == NULL || strsSize == 0) { return ans; } ans = (char *)malloc(sizeof(char) * (strlen(strs[0]) + 1)); m原创 2020-11-23 19:30:17 · 72 阅读 · 0 评论 -
13.leetcode 罗马数字转整数
typedef struct Conbination { char key; char value[2]; } Conbination; Conbination g_con[] = { {'I', 'V', 'X'}, {'X', 'L', 'C'}, {'C', 'D', 'M'}, }; int g_con_size = sizeof(g_con) / sizeof(g_con[0]); typedef struct Map { char key;原创 2020-11-23 18:54:42 · 74 阅读 · 0 评论