自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(34)
  • 资源 (1)
  • 收藏
  • 关注

原创 leetcode: 3 无重复字符的最长子串

int lengthOfLongestSubstring(char * s) { int len = strlen(s); if (len <= 1) { return len; } int hash[1024] = {0}; int left = 0; int right = 0; int max = 0; while (s[right] != '\0') { if (hash[s[right]] &.

2021-12-15 11:17:47 270

原创 开启进程core dumo 功能

头文件依赖:#include <sys/prctl.h>#include <sys/resource.h>1.设置进程可以dump prctl(PR_SET_DUMPABLE, 1);2.设置rlimit_core的大小 struct rlimit rlimit_core; rlimit_core.rlim_cur = RLIM_INFINITY; rlimit_core.rlim_max = RLIM_INFINITY; set.

2021-12-01 10:50:19 217

原创 leetcode: 1011. 在 D 天内送达包裹的能力

int getDays(int* weights, int weightsSize, int mid){ int days = 1; int count = 0; for (int i = 0; i < weightsSize; i++) { if ((count + weights[i]) > mid) { days++; count = 0; } count += we.

2021-10-30 08:57:47 107

原创 leetcode:62. 不同路径

https://leetcode-cn.com/problems/unique-paths/// 三步走// 1. 确定数组意义:dp[i][j] :从 (0,0) 到 (i,j)有多少条路径// 2. 找出关系式: dp[i][j] = dp[i-1][j] + dp[i][j-1]// 3. 初始值: dp[0][0] = 1// dp[i][0] = 1// dp[0][j] = 1int uniqu

2021-09-08 19:05:43 81

原创 suse、centos 软件包链接

centos 6.10的:https://vault.centos.org/6.10/os/x86_64/Packages/suse的https://opensuse.pkgs.org/15.2/opensuse-update-oss-x86_64/

2021-08-20 10:16:14 120

原创 leetcode: 237. 删除链表中的节点

// node就是要删除的节点, 且不是末尾结点// 直接将node->next的值赋给node,同时node->next = node->next->next;void deleteNode(struct ListNode* node) { struct ListNode *next = node->next; node->val = node->next->val; node->next = node->next.

2021-08-15 10:54:19 59

原创 leetcode: 283. 移动零

// 记录当前0的个数, 当遍历到非0时, 根据前面有几个0, 既能得知要往前挪几位void moveZeroes(int* nums, int numsSize){ if (NULL == nums || numsSize <= 1) return; int i; int zero_num = 0; for (i = 0; i < numsSize; i++) { if (nums[i] == 0) { zero_n.

2021-08-15 10:36:40 51

原创 leetcode: 11. 盛最多水的容器

利用双指针, 加一个临时最大值。临时最大值 = MIN(height[left] , height[right])* (right - left), 同时根据哪个矮就往前或者往后挪一位int maxArea(int* height, int heightSize){ if (NULL == height) return 0; if (heightSize < 2) return 0; int left = 0; int right = heightSi.

2021-08-15 10:24:39 64

原创 leetcode: 53. 最大子序和

#define MAX(a,b) (a) > (b) ? (a) : (b)int maxSubArray(int* nums, int numsSize){ int max = nums[0]; int sum = nums[0]; for (int i = 1; i < numsSize; i++) { if (sum < 0) { // 当前sum值小于0, 那么不管怎么加都会把后续的值变小, 所以直接置为0, 重新计算sum值 .

2021-08-06 11:04:00 62

原创 leetcode(动态规划):198. 打家劫舍

//1. 定义 dp[i]: 为到第i间房最多偷多少//2. 关系: 有两种偷法: 不偷:dp[i] = dp[i-1]// 偷:dp[i] = nums[i] + dp[i-2] // 前面一个房子不能偷// dp[i] = MAX(dp[i-1], nums[i] + dp[i-2])//3. 初始值// 只有一个房间,偷之: dp[0] = num[0]// 只有两个房间,偷其中金额较高的那个房间:.

2021-08-06 10:36:44 65

原创 leetcode(动态规划):64. 最小路径和

// 三步走// 1. 确定数组意义:dp[i][j] 当前走到dp[i][j]的最小路径// 2. 找出关系式: dp[i][j] = MIN(dp[i - 1][j], dp[i][j - 1]) + grid[i][j]// 3. 初始值: dp[0][0] = grid[0][0]// dp[i][0] = grid[i][0] + dp[i - 1][0];// dp[0][j] = grid[0][j] .

2021-08-05 15:33:07 69

原创 leetcode(动态规划):62. 不同路径

https://leetcode-cn.com/problems/unique-paths/// 动态规划三步走:// 1. 定义数组a[i][j]: 到a[i][j] 总共有多少条路径// 2. 找出数组元素关系:a[i][j] = a[i-1][j] + a[i][j - 1]// 3. 初始条件: a[0][0] = 0, a[0][j] = 1, a[i][0] = 1int uniquePaths(int m, int n) { if (m == 1 &amp

2021-08-05 11:07:54 85

原创 leetcode(回溯法):46. 全排列

/** * 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(). */ /*回溯法框架解题:result = []def.

2021-08-03 11:23:27 110

原创 leetcode(回溯法):17. 电话号码的字母组合

/** * Note: The returned array must be malloced, assume caller calls free(). */ /*回溯法框架解题:result = []def backtrack(路径, 选择列表): if 满足结束条件: result.add(路径) return for 选择 in 选择列表: 做选择 backtrack(路径, 选择列表) .

2021-08-02 16:35:24 70

原创 leetcode:98. 验证二叉搜索树

// 引入min和max// 左子树结点的最大值一定小于root->val// 右子树结点的最小值一定大于root->valbool isValidBSTSub(struct TreeNode *node, int min, int max) { if (NULL == node) return true; if (node->val < min || node->val > max) return false; if (node-&g.

2021-07-27 11:17:16 62

原创 leetcode:20. 有效的括号 (C语言)

利用栈, 注意边界// 将左括号入栈,一旦遇到右括号就出栈,出栈的元素与左括号不匹配,直接返错bool isValid(char * s){ char stack[10000] = {0}; int top = -1; while (*s != '\0') { if (*s == '(' || *s == '{' || *s == '[') { stack[++top] = *s; } if (*s =

2021-07-26 20:21:19 124

原创 leetcode: 86. 分隔链表

https://leetcode-cn.com/problems/partition-list//** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* partition(struct ListNode* head, int x){ if (NULL == head) retu

2021-07-23 15:30:03 62

原创 leetcode: 24. 两两交换链表中的节点

借用临时接节点/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* swapPairs(struct ListNode* head){ if (head == NULL || head->next == NULL) return head; struct Li

2021-07-23 11:03:22 67

原创 leetcode:82. 删除排序链表中的重复元素 II

struct ListNode* deleteDuplicates(struct ListNode* head){ if (head == NULL) return NULL; struct ListNode tmp; tmp.next = head; struct ListNode *cur = &tmp; while (cur->next && cur->next->next) { if (cur-&.

2021-07-20 20:29:17 78

原创 leetcode:19. 删除链表的倒数第 N 个结点(C语言)

/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */// 两个指针struct ListNode* removeNthFromEnd(struct ListNode* head, int n){ if (NULL == head || n == 0) return head; struct List...

2021-07-09 17:19:17 97

原创 leetcode: 83. 删除排序链表中的重复元素(C语言)

struct ListNode* deleteDuplicates(struct ListNode* head){ if (NULL == head) return head; struct ListNode *new_head = head; struct ListNode *next; while (head->next) { next = head->next; if (head->val == next->.

2021-07-09 12:42:28 277

原创 剑指 Offer 24. 反转链表

https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof//** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* reverseList(struct ListNode* head){ if (NULL == head)

2021-06-29 12:57:54 41

原创 leetcode:112. 路径总和(二叉树, C语言)

https://leetcode-cn.com/problems/path-sum//** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */bool myPathSum(struct TreeNode *node, int tmpSum) { //.

2021-06-18 11:45:08 126

原创 leetcode:102. 二叉树的层序遍历(C语言)

迭代:利用队列//利用队列, 先进先出#define MAX_NUM 10000int** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){ *returnSize = 0; if (NULL == root) return NULL; // 存放返回结果的二维数组 int **result = (int **)malloc(sizeof(int *) *

2021-06-17 15:04:21 492

原创 leetcode:144. 二叉树的前序遍历(C语言)

递归 #define MAX_NUM 100 int *result = NULL;void myPreOrder(struct TreeNode *root, int *returnSize){ if (root == NULL) return; result[(*returnSize)++] = root->val; myPreOrder(root->left, returnSize); myPreOrder(root->right, r

2021-06-15 15:24:49 120

原创 leetcode: 94. 二叉树的中序遍历(C: 递归+迭代)

https://leetcode-cn.com/problems/binary-tree-inorder-traversal/submissions/

2021-06-15 12:52:30 116

原创 leetcode: 1265. 逆序打印不可变链表(C语言)

利用双指针void printLinkedListInReverse(struct ImmutableListNode* head) { if (NULL == head) return; struct ImmutableListNode *slow; struct ImmutableListNode *fast; struct ImmutableListNode *fast_head = head->getNext(head); while (fas

2021-06-04 14:29:21 104

原创 leetcode: 23. 合并K个升序链表(C语言)

借用临时节点:将每次合并的都dugestruct ListNode* mergeKLists(struct ListNode** lists, int listsSize){ int i = 0; struct ListNode* pHeadNode = NULL; if ((NULL == lists) || (0 == listsSize)) { return NULL; } pHeadNode = (struct

2021-06-03 15:04:40 251 1

原创 剑指 Offer 25. 合并两个排序的链表(C语言)

临时节点/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2){ if (NULL == l1) return l2; if (NULL == l2) ret

2021-06-02 18:02:34 184

原创 leetcode: 1. 两数之和(C语言)

/** * Note: The returned array must be malloced, assume caller calls free(). */// 暴力解法int* twoSum(int* nums, int numsSize, int target, int* returnSize){ int *result = NULL; *returnSize = 0; for (int i = 0; i < numsSize - 1; i++) { .

2021-06-02 13:06:02 52

原创 leetcode:4. 寻找两个正序数组的中位数(C语言)

#define MAX_LEN 2000int nums[2000] = {0};void mergeArray(int *nums, int *numsSize, int* nums1, int nums1Size, int* nums2, int nums2Size){ int i = 0; int j = 0; int k = 0; while (i < nums1Size && j < nums2Size) { i.

2021-05-31 15:02:09 163

原创 letcode: 26. 删除有序数组中的重复项

int removeDuplicates(int* nums, int numsSize){ if (numsSize <= 1) return numsSize; int index = 0; int right = 1; while (index < numsSize && right < numsSize) { if (nums[index] != nums[right]) { ...

2021-05-31 10:38:44 45

原创 leetcode: 3. 无重复字符的最长子串(C语言)

双指针 + hashint lengthOfLongestSubstring(char * s){ int left = 0; int right = 0; int sum; int max = 0; int len = strlen(s); int hash[128] = {0}; while (right < len) { if (hash[s[right]] > 0) { sum =

2021-05-29 15:57:54 87

原创 leetcode:2. 两数相加(C实现)

最少空间:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; *//* 额外空间使用最小 */struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){ if (l1 == NULL) return l2; if (

2021-05-28 18:06:21 86

Distributed System BuildingBlocks

Distributed System BuildingBlocks, http://thu-cmu.cs.tsinghua.edu.cn/curriculum/dscourse/schedule.htm

2018-05-27

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除