llllmz

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

02 2024 档案

145. 二叉树的后序遍历c
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * Note: The ret 阅读全文

posted @ 2024-02-29 22:49 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

94. 二叉树的中序遍历c
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * Note: The ret 阅读全文

posted @ 2024-02-29 22:44 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

144. 二叉树的前序遍历c
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * Note: The ret 阅读全文

posted @ 2024-02-29 22:40 神奇的萝卜丝 阅读(2) 评论(0) 推荐(0) 编辑

150. 逆波兰表达式求值 C
摘要:int evalRPN(char** tokens, int tokensSize) { int* stack=(int*)malloc(sizeof(int)*tokensSize); for(int i=0;i<tokensSize;i++) stack[i]=0; int top=-1; fo 阅读全文

posted @ 2024-02-29 20:07 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0) 编辑

1047. 删除字符串中的所有相邻重复项 c
摘要:char* removeDuplicates(char* s) { int ns=0; while(s[ns]!=0) ns++; if(ns<=1) return s; char* stack=(char*)malloc(sizeof(char)*ns); for(int i=0;i<ns;i++ 阅读全文

posted @ 2024-02-29 19:31 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

225. 用队列实现栈 c
摘要:typedef struct { int a[100]; int top; int size; } MyStack; MyStack* myStackCreate() { MyStack* stack=(MyStack*)malloc(sizeof(MyStack)); stack->top=0; 阅读全文

posted @ 2024-02-29 19:21 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0) 编辑

232. 用栈实现队列 C
摘要:C用数组模拟即可 typedef struct { int a[100]; int front; int tail; int size; } MyQueue; MyQueue* myQueueCreate() { MyQueue* q=(MyQueue*)malloc(sizeof(MyQueue) 阅读全文

posted @ 2024-02-29 19:16 神奇的萝卜丝 阅读(7) 评论(0) 推荐(0) 编辑

459. 重复的子字符串 c
摘要:bool repeatedSubstringPattern(char* s) { int ns=0; while(s[ns]!=0) ns++; if(ns<=1) return false; bool same =true; char temp=s[0]; int i=1; for(;i<ns;i 阅读全文

posted @ 2024-02-29 17:36 神奇的萝卜丝 阅读(8) 评论(0) 推荐(0) 编辑

55. 右旋字符串 C
摘要:#include<stdio.h> void reverse(char* s,int head,int tail){ while(head<=tail){ char temp=s[head]; s[head]=s[tail]; s[tail]=temp; head++; tail--; } } ch 阅读全文

posted @ 2024-02-29 14:37 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

151. 反转字符串中的单词 c
摘要:现在解决一个中等难度的题得要30min,争取在复试的时候提升到只有15min!!!! void revesestring(char* s,int head,int tail){ while(head<=tail){ char temp=s[head]; s[head]=s[tail]; s[tail 阅读全文

posted @ 2024-02-29 14:08 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

54. 替换数字 C
摘要:#include<stdio.h> int main(){ char c[10000]; scanf("%s",c); int i=0; while(c[i]!=0){ int t=c[i]-'0'; if(0<=t&&t<=9){ printf("number"); }else{ printf(" 阅读全文

posted @ 2024-02-29 12:55 神奇的萝卜丝 阅读(16) 评论(0) 推荐(0) 编辑

541. 反转字符串 II C
摘要:void reverse_string(char* s,int head,int tail){ while(head<=tail){ char t=s[head]; s[head]=s[tail]; s[tail]=t; head++; tail--; } } char* reverseStr(ch 阅读全文

posted @ 2024-02-29 12:43 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

344. 反转字符串C
摘要:void reverseString(char* s, int sSize) { int head=0,tail=sSize-1; while(head<=tail){ char t=s[head]; s[head]=s[tail]; s[tail]=t; head++; tail--; } } 1 阅读全文

posted @ 2024-02-28 22:33 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

454. 四数相加 II C
摘要:自己写了一个hash表。 原来学过的数据结构关于hash的那章还是有实际用的,不是书架子。 typedef struct node{ int sum; int count; struct node* repeatnext; }hash; void init_hashtable(hash h[]){ 阅读全文

posted @ 2024-02-28 22:05 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

202. 快乐数 C
摘要:没有意识到这是一个环。 原理就是,其区间是有限的(int型变量存在最大值pow(2,31)-1),而循环却是无限的,那么一定会发生重复的情况。 如果不重复,那么和区间有限矛盾。 int c_sum(int n){ int sum=0; while(n!=0){ int t=n%10; n/=10; 阅读全文

posted @ 2024-02-28 20:47 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

350. 两个数组的交集 II C
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ int min(int i,int j){ if(i<j) return i; return j; } int* intersect(int 阅读全文

posted @ 2024-02-28 20:24 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

349. 两个数组的交集C
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size 阅读全文

posted @ 2024-02-28 20:07 神奇的萝卜丝 阅读(7) 评论(0) 推荐(0) 编辑

383. 赎金信C
摘要:\ int hash(char c){ return c-'a'; } bool canConstruct(char* ransomNote, char* magazine) { if(!ransomNote) return true; if(!magazine) return false; int 阅读全文

posted @ 2024-02-28 19:58 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0) 编辑

242. 有效的字母异位词 C
摘要:int hash(char c){ return c-'a'; } bool isAnagram(char* s, char* t) { int a[26]={0}; int b[26]={0}; int i=0; while(s[i]!=0){ a[hash(s[i++])]++; } i=0; 阅读全文

posted @ 2024-02-28 17:54 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

142. 环形链表 II C
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode *detectCycle(struct ListNode 阅读全文

posted @ 2024-02-28 17:47 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

面试题 02.07. 链表相交C
摘要:利用链表的特性,如果相交的话,后面就不可能岔开! 你可以想象把他们有同一个尾巴,然后从尾巴往前看。 所以只要知道两个链表的长度,就可以在同一起跑线上一起比较了。 /** * Definition for singly-linked list. * struct ListNode { * int va 阅读全文

posted @ 2024-02-28 16:47 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

19. 删除链表的倒数第 N 个结点C
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* removeNthFromEnd(struct List 阅读全文

posted @ 2024-02-28 16:30 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0) 编辑

24. 两两交换链表中的节点C
摘要:没必要纠结太麻烦的方法。 简单的就两种,一个就是新拿出来空间来装。 要不然就是直接前后数据换一下就行了。 然后需要考虑表空的情况。 结果: /** * Definition for singly-linked list. * struct ListNode { * int val; * struct 阅读全文

posted @ 2024-02-28 16:13 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

206. 反转链表C
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* reverseList(struct ListNode* 阅读全文

posted @ 2024-02-28 15:58 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0) 编辑

203. 移除链表元素C
摘要:写了个递归 /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* delect(struct ListNode 阅读全文

posted @ 2024-02-28 13:39 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

59. 螺旋矩阵 IIC
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a 阅读全文

posted @ 2024-02-28 13:30 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

76. 最小覆盖子串C
摘要:int hash(char c){ return c-'A'+1; } bool judge_Same(int a[],int b[]){ for(int i=0;i<200;i++){ if(b[i]!=0 && b[i]>a[i]) return false; } return true ; } 阅读全文

posted @ 2024-02-27 21:18 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

904. 水果成篮C
摘要:int totalFruit(int* fruits, int fruitsSize) { if(fruitsSize<=2) return fruitsSize; int a[2]={-1,-1};//蓝子空 int max=0,n=1; int head=0, tail=0;//从head摘到t 阅读全文

posted @ 2024-02-27 16:14 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

209. 长度最小的子数组C
摘要:滑动窗口的妙用!! int minSubArrayLen(int target, int* nums, int numsSize) { int sum=nums[0];//区间head到tail的和 int head=0,tail=0; int minn=numsSize; int tag=0; i 阅读全文

posted @ 2024-02-27 15:04 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

977. 有序数组的平方
摘要:学习了下用qsort解决。 /** * Note: The returned array must be malloced, assume caller calls free(). */ int cmp(const void* a,const void* b){ return *(int*)a-*( 阅读全文

posted @ 2024-02-27 13:39 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

844. 比较含退格的字符串C
摘要:这题学到了很多。 malloc后要初始化。 申请字符串要N+1个单位 字符串以0结尾等等 char* final(char* s,int n){ char* tem=(char*)malloc(sizeof(char)*(n+1)); for(int i=0;i<=n;i++) { tem[i] = 阅读全文

posted @ 2024-02-27 13:15 神奇的萝卜丝 阅读(10) 评论(0) 推荐(0) 编辑

26. 删除有序数组中的重复项C
摘要:int removeDuplicates(int* nums, int numsSize) { if(numsSize==0||numsSize==1) return numsSize; int i=0,j=0; int pre=-999,n=0; while(j<numsSize){ if(num 阅读全文

posted @ 2024-02-26 19:35 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0) 编辑

367. 有效的完全平方数C
摘要:bool isPerfectSquare(int num) { if(num==1) return true; if(num==2) return false; long head=2,tail=num-1; while(head<=tail){ long mid=(head+tail)/2; lo 阅读全文

posted @ 2024-02-26 19:18 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

69. x 的平方根 C
摘要:int mySqrt(int x) { return sqrt(x); } 阅读全文

posted @ 2024-02-26 19:11 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

34. 在排序数组中查找元素的第一个和最后一个位置C
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ int* searchRange(int* nums, int numsSize, int target, int* returnSize) 阅读全文

posted @ 2024-02-26 19:08 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

35. 搜索插入位置C
摘要:int searchInsert(int* nums, int numsSize, int target) { int head=0,tail=numsSize-1; while(head<=tail){ int mid=(head+tail)/2; if(nums[mid]<target){ he 阅读全文

posted @ 2024-02-26 17:08 神奇的萝卜丝 阅读(2) 评论(0) 推荐(0) 编辑

27. 移除元素C
摘要:原本我想用头尾交换的双指针的,但是又要判断头尾是否相等,感觉不干净的感觉。 就换成了类似筛选的前后双指针。一个是指向要放的位置,一个指向查看的位置。 int removeElement(int* nums, int numsSize, int val) { int i=0,j=0; while(j< 阅读全文

posted @ 2024-02-26 16:58 神奇的萝卜丝 阅读(8) 评论(0) 推荐(0) 编辑

704. 二分查找C
摘要:现在开始刷代码随想录里的题了。 int search(int* nums, int numsSize, int target) { int head=0,tail=numsSize-1; while(head<=tail){ int mid=(head+tail)/2; if(nums[mid]<t 阅读全文

posted @ 2024-02-26 16:46 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

438. 找到字符串中所有字母异位词C
摘要:今天出成绩了,感觉徘徊在被刷的边缘,要好好努力了。 这题我想法试建立hash映射成有序的数字,只要字符串个数相同,并且映射和相同那么就是异位串。 后来这个想法是错的。以为假设已经已知一个和,和组成这个和的个数,但这个子数并不唯一,比如10=1+2+7。10=2+3+5。 这样就会误判。就算能找到唯一 阅读全文

posted @ 2024-02-26 16:26 神奇的萝卜丝 阅读(14) 评论(0) 推荐(0) 编辑

3. 无重复字符的最长子串C++
摘要:思路就是从头开始找,然后每次在从重复节点的后一个找。 class Solution { public: int lengthOfLongestSubstring(string s) { int i=0,j=0,nowmax=1; int max=1; if(s.size()==0||s.size() 阅读全文

posted @ 2024-02-24 19:33 神奇的萝卜丝 阅读(9) 评论(0) 推荐(0) 编辑

42. 接雨水C
摘要:因为还是双指针的题目。 我想到的短板效应,看两头,能接住的水也就是取决于最短的一方。 每次看两头后,在里面找比最短还短的地方,那个就是有水的地方。找到水后在把它填平,防止重复找到。然后两头往中间靠就行了。 int min(int i,int j){ if(i>j) return j; return 阅读全文

posted @ 2024-02-23 15:58 神奇的萝卜丝 阅读(7) 评论(0) 推荐(0) 编辑

15. 三数之和C++
摘要:先排序,再暴力找就好了。如果当前元素大于0或者前两个元素和大于0就不用找了。然后结果超时了。 然后借鉴了双指针的解法,发现双指针其实就是把单向循环优化成双向循环。 class Solution { public: vector<vector<int>> threeSum(vector<int>& n 阅读全文

posted @ 2024-02-23 15:16 神奇的萝卜丝 阅读(9) 评论(0) 推荐(0) 编辑

11. 盛最多水的容器C++
摘要:原本想o(n2)遍历的,结果超时了,果然没这么简单就解决。 class Solution { public: int s(vector<int> height,int i,int j){ int s1=min(height[i],height[j])*(j-i); return s1; } int 阅读全文

posted @ 2024-02-22 20:59 神奇的萝卜丝 阅读(8) 评论(0) 推荐(0) 编辑

283. 移动零C
摘要:类似像一个筛选过程,如果非0就加入数组,不非0就不加。 void moveZeroes(int* nums, int numsSize) { int x=0,y=0; while(x<numsSize){ if(y>=numsSize) break; if(nums[y]!=0){ nums[x]= 阅读全文

posted @ 2024-02-22 20:31 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

4.3 提升题 - A One Way In, Two Ways OutC++
摘要:就是让你判断输入受限的双端队列的输出的正确性。 其实就是模拟双端队列出队的过程,要不左边出队,要不右边出队,而入队已经一定了。 用一个数组模拟输入受限的双端队列就行了。 但是写这题可太难受了,写了我大概2个半小时,各种各种小错误,没考虑周全的地方。 #include<iostream> using 阅读全文

posted @ 2024-02-21 21:43 神奇的萝卜丝 阅读(21) 评论(0) 推荐(0) 编辑

128. 最长连续序列C
摘要:o(n)现在水平不够。 采用先快排序,再找。O(nlogn),注意每次划分枢纽选择中间节点(中间节点和首节点互换) int divide(int* nums,int head,int tail){ int x=nums[(head+tail)/2]; nums[(head+tail)/2]=nums 阅读全文

posted @ 2024-02-21 19:56 神奇的萝卜丝 阅读(19) 评论(0) 推荐(0) 编辑

49. 字母异位词分组c++
摘要:刷力扣还有点不太习惯,主要是C++只学了皮毛。 看了官方活用map就是好啊。 把字母都排好序 然后判断就好了。 map<string,vector<string>> m; for(int i=0;i<strs.size();i++){ string tem=strs[i]; sort(tem.beg 阅读全文

posted @ 2024-02-21 18:40 神奇的萝卜丝 阅读(8) 评论(0) 推荐(0) 编辑

1. 两数之和C
摘要:原本想排下序的,但要求返回下标,又感觉要添加其他东西了,太麻烦了。暴力找就好了。 阅读全文

posted @ 2024-02-21 15:03 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

DP19 最长公共子序列(一)C
摘要:建议直接网上看思路.... #include<stdio.h> int max(int i,int j){ if(i>j) return i; return j; } int maxlength[1001][1001]; int main(){ int n,m; while(scanf("%d %d 阅读全文

posted @ 2024-02-19 15:39 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

KY78 最大上升子序列和C++
摘要:这个解决问题的思路使用动态规划,即用已知状态去得到未知状态。 思路逻辑是这样 sum[i]记录以A[i]为末上升子序列的和的最大值 然后从j 从 0-i-1 遍历 如果A[j]<A[i] 那么 sum[i]=sum[j]+A[i]; 然后找出sum[i]中的的最大值,就是以A[i]为末上升子序列的和 阅读全文

posted @ 2024-02-19 14:24 神奇的萝卜丝 阅读(11) 评论(0) 推荐(0) 编辑

KY22 最大序列和C
摘要:题目例子给的很好,还有不要遗漏全是负数的情况。 #include<stdio.h> #include<math.h> int main(){ long long n=0; while(scanf("%ld",&n)!=EOF){ long long sum=0; long long max=0; i 阅读全文

posted @ 2024-02-18 18:37 神奇的萝卜丝 阅读(70) 评论(0) 推荐(0) 编辑

KY225 N阶楼梯上楼问题C++
摘要:#include<iostream> using namespace std; int main(){ int n=0; int f[90]; f[1]=1; f[2]=2; while(cin >> n){ for(int i=3;i<=n;i++){ f[i]=f[i-1]+f[i-2]; } 阅读全文

posted @ 2024-02-18 18:07 神奇的萝卜丝 阅读(7) 评论(0) 推荐(0) 编辑

畅通工程续C
摘要:考迪杰斯特拉算法。 #include<stdio.h> struct node{ int n1; int n2; int weight; }; typedef struct node edge; edge e[1000]; void init_dist(int dist[],int n){ for( 阅读全文

posted @ 2024-02-18 17:15 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

KY148 还是畅通工程C++
摘要:求图的最小生成树。克鲁斯卡尔算法来解决。就是选择n-1条最小边且无回路。 回路判断用并查集就行。 即要加入的边(两个节点)具有相同的父节点说明如果这两个节点本来就存在路径,再加入一条边就会产生回路,舍去。 #include<iostream> #include<algorithm> using na 阅读全文

posted @ 2024-02-18 16:29 神奇的萝卜丝 阅读(22) 评论(0) 推荐(0) 编辑

KY175 连通图C
摘要:最近实在是太偷懒了,再这样下去复试直接寄。要努努力了。 简单一点可以用并查集,不嫌麻烦DFS/BFS都可以判断是否连通。 #include<stdio.h> void swap(int* x,int* y){ if(*x >*y){ int t=*x; *x=*y; *y=t; } } int fa 阅读全文

posted @ 2024-02-15 15:04 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

A Knight's JourneyC++
摘要:题目看半天看不懂。 題目把我恶心坏了。看网上说按字典顺序输出,到底是什么意思半天没搞懂。 #include<iostream> #include<string> using namespace std; int d[8][2]={ {-1,-2},{1,-2},{-2,-1},{2,-1},{-2, 阅读全文

posted @ 2024-02-03 23:05 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

Find The MultipleC++
摘要:这题就是找N的倍数m,M要求是由1和0组成且非0。 可以用图来看,从1出发临边是1和0,然后广度遍历,第一个能能整除N的数输出就行。 #include<iostream> #include<queue> using namespace std; int main(){ int n=-1; while 阅读全文

posted @ 2024-02-03 16:35 神奇的萝卜丝 阅读(10) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示