leetcode977. 有序数组的平方报错
AddressSanitizer: heap-buffer-overflow on address 0x602000000514 at pc 0x000000367537 bp 0x7ffc2eb12910 sp 0x7ffc2eb12908 READ of size 4 at 0x602000000514 thread T0 #2 0x7f650291b082 (/lib/x86_64-linux-gnu/libc.so.6+0x24082) 0x602000000514 is located 0 bytes to the right of 4-byte region [0x602000000510,0x602000000514) allocated by thread T0 here: #6 0x7f650291b082 (/lib/x86_64-linux-gnu/libc.so.6+0x24082) Shadow bytes around the buggy address:
我是用空间换时间的方法写这道题的, 遇到了一个内存访问越界的报错
int i = 0;
while( nums[i] <0){
i++;
}
我当成数组来处理了,忽略了此时的越界情况
只需要加上
` i<nums.size() &&`