编程错误
LeetCode 代码错误
错误:
Line 1060: Char 9: runtime error: addition of unsigned offset to 0x7ffd5a832640 overflowed to 0x7ffd5a83263f (basic_string.h)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/..b/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/basic_string.h:1070:9
错误原因:
因为后面用到两个数组下标i,j,for中的两个变量判断时不能使用逗号,应该用&&
- 错误代码:
for(i=num1.size()-1,j=num2.size()-1;i>=0,j>=0;i--,j--){
......
}
- 正确代码:
for(i=num1.size()-1,j=num2.size()-1;i>=0&&j>=0;i--,j--){
......
}