摘要: code: int maxProduct(char ** words, int wordsSize){ int a[wordsSize]; //目标字符串转换成整型数组元素 int maxlen = 0; //最大长度乘积 for(int i = 0; i < wordsSize ;++i){ // 阅读全文
posted @ 2023-11-07 22:27 2B青年~ 阅读(26) 评论(0) 推荐(0)
摘要: 123456 -> 456123,相当于是将数据形成了一个环,对于这些数据for(i = 0;i<n;++i), 想回到第几位,就这样写 i = (i + target )% n;不加target相当于成环但是位次没有移动,target为移动的长度; 阅读全文
posted @ 2023-11-04 10:19 2B青年~ 阅读(20) 评论(0) 推荐(0)
摘要: code: #include <stdio.h>#include <malloc.h>#include <string.h>char *CanTwo(int n) //其实应该定义为字符串常量,因为yes和no定义后不能再改变,变就是定义成字符串数组{ char *a="YES"; char *b= 阅读全文
posted @ 2023-11-03 16:48 2B青年~ 阅读(33) 评论(0) 推荐(0)
摘要: 我的错误:将问题中引入了if语句,是问题变复杂了 优解: int* shuffle(int* nums, int numsSize, int n, int* returnSize){ int *ret = (int*)malloc(sizeof(int)*n*2); *returnSize = nu 阅读全文
posted @ 2023-10-29 12:48 2B青年~ 阅读(20) 评论(0) 推荐(0)
摘要: 回车符等部分符号,有转义字符,如果是将字符直接输入,可能会造成数据因空间不够而丢失,如输入n个字符,只给了n个位置,当含有一个回车字符时,字符长度为n + 1,导致我的结果错误,丢失了一个符合要求的数据 阅读全文
posted @ 2023-10-26 20:07 2B青年~ 阅读(21) 评论(0) 推荐(0)
摘要: 普通分隔符: 分号「 ; 」:语句结尾 大括号「 { } 」:函数体,复合语句以及数组的初始化等; 圆括号「 () 」:函数定义时用来括住参数,或者用来修改运算顺序, 比如:(a + 1) 2 和 a + (1 2) 方括号「 [] 」定义数组类型和应用元素,比如: int a10; b = a3; 阅读全文
posted @ 2023-10-26 18:17 2B青年~ 阅读(106) 评论(0) 推荐(0)
摘要: my code: int f[46]; int climbStairs(int n){ f[0] = 1; f[1] = 1; int i; for(i = 2 ; i <= n ; ++i){ f[i] = f[i - 1] + f[i - 2]; }return f[n]; //原来写的是f [ 阅读全文
posted @ 2023-10-26 11:01 2B青年~ 阅读(17) 评论(0) 推荐(0)
摘要: my code: int kthFactor(int n, int k){ int i,time = 0,max = 0; for(i = 1;i <= n; ++i){ if (n % i == 0 ){ time++; max = max > i ? max : i; } if (time == 阅读全文
posted @ 2023-10-26 10:30 2B青年~ 阅读(24) 评论(0) 推荐(0)
摘要: 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。返回这个结果。 my code:忽略了num为零;不知道如何对不为一位数的结果再次循环; 正解: int addDigits(int num){ while(1){ int ans = 0; while(num){ ans += 阅读全文
posted @ 2023-10-26 01:15 2B青年~ 阅读(103) 评论(0) 推荐(0)
摘要: my code: bool isPowerOfTwo(int n){ int target = 1,i; if (n <= 0){ return false; } for(i = 1;i != 1073741824;i *= 2){ if(i == n ){ return true; } }retu 阅读全文
posted @ 2023-10-26 00:49 2B青年~ 阅读(11) 评论(0) 推荐(0)