LeetCode上面写的代码有时候出错了,非常不好定位,只能printf打印,而不能单步调试和设置断点。
能不能本地IDE调试LeetCode代码呢?当然能,例如现在用vscode来调试LeetCode代码。
首先得电脑得安装gcc,vscode配置好gcc和gdb,网上教程非常多,这里不详细说明了。
然后就是添加对应头文件:
#include <ctype.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
接着就是写个main函数调用LeetCode的函数了,但是这里需要小心二维数组传参处理。
以 14. 最长公共前缀(E),这道题为例,整个文件代码如下:
#include <securec.h>
#include <ctype.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
char * longestCommonPrefix(char ** strs, int strsSize) {