LeetCode 38题Count and Say的C语言解法存疑,附我的AC代码
关于LeetCode第38题Count and Say的C语言解法困惑
最近在刷LeetCode第38题Count and Say的时候,我用C语言写了解法,虽然AC了,但还是对其中的一些细节感到困惑。下面是我的AC代码(我自己写了main函数测试,提交时只需要复制countAndSay函数就行):
#include <stdio.h> #include <limits.h> #include <stdlib.h> #include <string.h> char* countAndSay(int n) { if( n == 1 ) return "1"; char *cur = (char *)malloc(2*sizeof(char)); char *res; cur[0]='1'; cur[1]='\0'; int len, idx, j, count; for(int i = 2; i <= n; ++i) { len = strlen(cur); res = (char *)malloc(len * 2 + 1); memset(res, '\0', l...
内容的提问来源于stack exchange,提问作者52coder
相关产品推荐
相关产品推荐

