文章分类 -  leetcode刷题

摘要:采用同向双指针 int lengthOfLongestSubstring(char * s){ int map[256] = {0}; int l, r; l = r = 0; int maxlen = 0; int len = strlen(s); while(r < len) { map[s[r 阅读全文
posted @ 2022-12-08 15:07 cn风 阅读(27) 评论(0) 推荐(0)
摘要:此题是可以理解为查找、添加类题目,是典型的hash做法,可以使用uthash来实现,代码如下: typedef struct { int key; int val; UT_hash_handle hh; } my_hash; my_hash *g_user; int* twoSum(int* num 阅读全文
posted @ 2022-01-26 11:45 cn风 阅读(43) 评论(0) 推荐(0)
摘要:if(isdigit(s[i])) { while(isdigit(s[i])) { int cur = s[i] - '0'; if(ret < div || ret == div && cur < 8) { ret = ret * 10 + (s[i] - '0'); i++; } else { 阅读全文
posted @ 2021-01-18 19:38 cn风 阅读(5) 评论(0) 推荐(0)
摘要:该题和875题爱吃香蕉的珂珂是同类题目,采用二分查找方式 特点:有序,找右边界 int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int canputballbyspace(int *position, i 阅读全文
posted @ 2021-01-16 16:38 cn风 阅读(55) 评论(0) 推荐(0)
摘要:本题属于数组类的题目,主要考查排序算法。 ##分发饼干 题目分类,个人感觉这是一个数组类的题,考查了排序算法; 先对g和s进行从小到大的排序; 遍历g和s, 直到某一个被遍历完即结束; 这里有一个注意的地方就是如果s[j]比g[i]小的情况,只递增j的记号,主要考虑用例如下: [5,6,7,8,9] 阅读全文
posted @ 2020-12-25 19:26 cn风 阅读(102) 评论(0) 推荐(0)
摘要:解题思路: 1、暴力统计单词个数和长度,使用strcpy到结构体字符串中,结果超时; 2、改变思路,第一遍遍历数组,获取单词个数、起始位置和单词长度,存放在结构体中; 3、对结构体进2次排序,标准做法,第一次排长度,第二次排起始位置; 4、第二次遍历结构体数组,赋值给结果res中; 详细代码如下: 阅读全文
posted @ 2020-12-24 19:34 cn风 阅读(135) 评论(0) 推荐(0)