![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C
文章平均质量分 76
rannrann
这个作者很懒,什么都没留下…
展开
-
【Leetcode&C&并查集】959. Regions Cut By Slashes
问题入口https://leetcode.com/problems/regions-cut-by-slashes/实现这道题是对并查集的练习。并查集两个重要操作是Union和find。而合并什么是个问题。合并线段,将连在一起的线段合并为一个集合,这样就能得到线段数,但是线段数和区域数之间不是线性关系。例如下图(黑线用来划分网格,红线是题目给过的参数),线段数分别是2和5,但是区域数都是4。而合并区域的话,如果还把网格看成一个整体就没办法合并。解决方案是把一个网格分成四个三角形,不论红线是原创 2020-10-29 14:12:22 · 120 阅读 · 0 评论 -
【Leetcode&C&Tire】677. Map Sum Pairs
问题入口实现通过递归很好解决该问题,但是由于遍历次数过多引发了Runtime Error(ps:这是用C语言编写的情况下),所以需要寻找其他解决方法。在我原本使用递归思路解决问题时,我对MapSum结构体定义如下:struct MapSum{MapSum **next; int value;};value>0(题目给的值都是正数)就表达了这个单词的值,同时也说明这是单词的结尾。等于一个属性参与了两个动作。如果我把每次加入的值都加在每一个字母上又会如何呢...原创 2020-10-05 16:13:24 · 100 阅读 · 0 评论 -
【Leetcode&C语言&Tire】208.Implement Trie (Prefix Tree) & 211.Design Add and Search Words Data Structure
这两道题难度是递进的关系,所以适合一起说。以下为题目入口208.Implement Trie (Prefix Tree)211.Design Add and Search Words Data Structure目录208.Implement Trie (Prefix Tree)实现211.Design Add and Search Words Data Structure实现208.Implement Trie (Prefix Tree)实现...原创 2020-09-27 13:19:28 · 162 阅读 · 0 评论 -
【memset()应用】C语言初始化自定义结构的野值
typedef struct TestMap TestMap;struct TestMap { int k; int v;};int main(){ int **test = (int **)malloc(sizeof(int*) * 2); if (test[0] == NULL) printf("without memset: test[0]==NULL\n");\\不显示 free(test); TestMap **tm = (TestMap **)malloc(sizeo.原创 2020-09-13 13:06:52 · 190 阅读 · 0 评论 -
【Leetcode&C语言】347. Top K Frequent Elements
问题描述Given a non-empty array of integers, return thekmost frequent elements.非空的整型数组,返回K个出现次数最频繁的元素举例说明Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]注意You may assumekis ...原创 2020-09-07 18:24:04 · 209 阅读 · 0 评论 -
【Leetcode&C语言】973. K Closest Points to Origin
目录问题描述举例说明限制实现谁能告诉我它的时间复杂度问题描述We have a list ofpointson the plane. Find theKclosest points to the origin(0, 0).(Here, the distance between two points on a plane is the Euclidean distance.)You may return the answer in any order....原创 2020-09-07 17:57:38 · 184 阅读 · 0 评论 -
【srand()应用】C语言随机生成不重复的10个1到100的数
代码int main(){ int n = 10; int array[10]; for (int i = 0; i < n; i++) { srand(i); array[i] = rand() % 100 + 1; } for (int i = 0; i < n; i++) { printf("%d\n", array[i]); } return 0;}结果误区范围在[1,100],随机数为rand()%100+1。范围在[a,b.原创 2020-09-06 14:52:57 · 10188 阅读 · 1 评论 -
C语言数组元素交换
代码void swap_element(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp;}int main(){ int a[2] = { 1,2 }; swap_element(a+0, a+1); printf("a[0]=%d,a[1]=%d\n", a[0], a[1]); return 0;}原创 2020-09-06 12:02:02 · 7130 阅读 · 0 评论 -
【C语言报错】C2232——内存分配与“.“和“->“的关系
typedef struct TestMap TestMap;struct TestMap { int k; int v;};int main(){ TestMap *test = (TestMap*)malloc(sizeof(TestMap) * 2); for (int i = 0; i < 2; i++) { test[i]->k = i+1;//C2232 “->k”: 左操作数有“struct”类型,使用“.” test[i]->v =...原创 2020-08-27 13:09:38 · 647 阅读 · 2 评论 -
【二分搜索树&C语言】以非递归的方式删除最大值,返回最大值
方案一这个方案我不放心的原因是,ancestor和parent是new出来的,放在堆里的,所以要释放。因为最后要返回ancestor->right,所以不能释放ancestor。这样应该是不行的。那你除非返回的是ancestor。随后释放的时候还是一个麻烦。返回给root以后方案二代码实现//以非递归的方式删除最大值,返回最大值int BST_removeMaxNR(BST *bst,lrNode *node) { if (node->right == N.原创 2020-07-29 16:12:14 · 186 阅读 · 0 评论 -
【Leetcode&C语言】235. Lowest Common Ancestor of a Binary Search Tree
目录问题描述举例描述实现问题描述Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and qas the...原创 2020-07-29 16:04:57 · 115 阅读 · 0 评论 -
【理解】二分搜索树的非递归后序遍历
void BST_postOrderNR(BST *bst) { ArrayStack *as = create_array_stack(10); lrNode *node = bst->root; lrNode *pre = NULL; while (!arrayStack_isEmpty(as) || node != NULL) { while (node != NULL) { push(as, node); node = node->left; } lrN.原创 2020-07-28 09:51:37 · 153 阅读 · 0 评论 -
【C语言问题】条件为真时无法进入while循环
问题描述没有报错,但不能进入while循环,while(isEmpty(array))中的isEmpty方法返回值和调试时的监视值不一样。解决方法检查一下实现isEmpty方法的XXX.c文件和声明文件XXX.h中的方法名是否一致。我是真的想截图,但是改好运行之后,再次模拟错误情况就会报错(为什么第一次不报错啊喂)。...原创 2020-07-26 16:59:39 · 1549 阅读 · 0 评论 -
【C语言报错】C2040间接寻址级别不同
错误写法void BST_add(BST *bst,int e) { bst->root = lrnode_add(bst,bst->root, e);//lrnode_add方法定义在后面}//向以node为根的二分搜索树中插入元素e,递归算法//返回插入新节点后二分搜索树的根lrNode* lrnode_add(BST *bst, lrNode *node, int e) { if (node == NULL) { bst->size++; return..原创 2020-07-25 12:53:55 · 6348 阅读 · 2 评论 -
【Leetcode&C语言】203. Remove Linked List Elements
目录问题描述举例说明思路实现结果问题描述Remove all elements from a linked list of integers that have valueval.删除链表中整数为val的元素。举例说明Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5思路 删除链表中的元素的一个思...原创 2020-07-17 14:50:32 · 130 阅读 · 0 评论 -
【C语言报错】C2061发生在结构声明的情况
报错错误写法typedef struct Node { B e; Node *next;}Node;正确写法typedef struct Node Node;struct Node { B e; Node *next;};原创 2020-07-10 16:24:28 · 354 阅读 · 0 评论 -
【leetcode&C语言】457. Circular Array Loop
问题描述You are given acirculararraynumsof positive and negative integers. If a numberkat an index is positive, then move forwardksteps. Conversely, if it's negative (-k), move backwardksteps. Since the array is circular, you may assume that the l...原创 2020-07-08 17:43:10 · 113 阅读 · 0 评论 -
【Leetcote&感想】155. Min Stack(无实现)
问题描述Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. getMin() -- Retrieve the m.原创 2020-07-02 17:33:04 · 107 阅读 · 0 评论 -
【leetcode&C语言】189. Rotate Array
目录问题描述举例说明限制思路实现反思问题描述Given an array, rotate the array to the right byksteps, wherekis non-negative.Follow up:Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could y...原创 2020-06-17 18:55:18 · 120 阅读 · 0 评论 -
【Leetcode&C语言】448. Find All Numbers Disappeared in an Array
问题描述Given an array of integers where 1 ≤ a[i] ≤n(n= size of array), some elements appear twice and others appear once.Find all the elements of [1,n] inclusive that do not appear in this array.Could you do it without extra space and in O(n) runti...原创 2020-06-12 19:42:11 · 140 阅读 · 0 评论 -
【Leetcode&C语言】665. Non-decreasing Array
目录问题描述举例说明限制思路实现反思问题描述Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every ...原创 2020-06-12 18:51:19 · 167 阅读 · 0 评论