【C语言刷LeetCode】用vscode调试LeetCode代码

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

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值