讨论/技术交流/执行代码成功,但是提交代码失败是为什么呢?/
执行代码成功,但是提交代码失败是为什么呢?

各位大佬好,小弟初次使用力扣。我做算法时,执行代码输出结果和预期结果是一致的,但是提交代码却报错了,请问是什么原因呢?

1
共 8 个回复

哦哦,所以测试例子得自己多试几组是么?

1

个别测试用例没通过吧,可以看具体哪条测试用例没过,在本地调试一下看看问题在哪

这是个比较常见的问题,可以百度下,会有很多相关博客写的很清楚了。

多考虑一些边缘情况

要综合考虑代码有没有满足所有实例的情况,有些比如重复、回文、空测试实例,没有考虑到的话报错证明代码写的还是不完善

报错信息如下

==42==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000001b0 at pc 0x5627e98eb4b6 bp 0x7ffc72edc300 sp 0x7ffc72edc2f0
READ of size 4 at 0x6020000001b0 thread T0
#2 0x7f45e912e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
0x6020000001b1 is located 0 bytes to the right of 1-byte region [0x6020000001b0,0x6020000001b1)
allocated by thread T0 here:
#0 0x7f45e9d73bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
#3 0x7f45e912e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
Shadow bytes around the buggy address:
0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff8000: fa fa 00 04 fa fa fd fa fa fa fd fa fa fa fd fa
0x0c047fff8010: fa fa 00 fa fa fa fd fa fa fa fd fa fa fa fd fa
0x0c047fff8020: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 00 00
=>0x0c047fff8030: fa fa fd fa fa fa[01]fa fa fa 04 fa fa fa fa fa
0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==42==ABORTING

执行的是当前一个实例,提交的时候会跑很多很多实例,你肯定有没有满足的实例情况

没有报错信息?