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) {
int minLen;
int len;
int minIndex = 0;
int i, j;
char *preStr = malloc(1024

本文介绍了如何使用VSCode本地调试LeetCode上的C语言代码,包括配置GCC和GDB,添加头文件,创建main函数调用LeetCode函数,并处理二维数组参数。通过示例展示了对于一道最长公共前缀问题的调试过程,以及如何处理其他OJ平台的输入重定向。

380

被折叠的 条评论
为什么被折叠?



