堆溢出?
#include <stdio.h>#include <stdlib.h>
#include <stdbool.h>
//https://leetcode-cn.com/problems/container-with-most-water/
int maxArea(int* height, int heightSize) {
int i, j, area;
for(i = 0; i < heightSize; ++i){
for(j = heightSize; j > i; --j){
int carea = (j-i) * (height < height? height : height);
area = carea > area? carea : area;
}
}
return area;
}
int main(int argc, char **argv){
int n[] = {1,8,6,2,5,4,8,3,7};
printf("%d\n", maxArea(n, 9));
return 0;
}
leetcode报
AddressSanitizer: heap-buffer-overflow on address 0x604000000034 at pc 0x00000040174e bp 0x7ffff6f2da60 sp 0x7ffff6f2da58
我用devcpp编译正常49
MingGW-gcc编译1971416003
八成是有错, 晕~~
求解 ...好吧我要去换一个编译器了 人造人 发表于 2019-3-6 23:47
多谢...我去换编译器了{:5_99:} 人造人 发表于 2019-3-6 23:47
不过最主要的还是下标越界{:5_103:}
页:
[1]