runtime error: reference binding to null pointer of type ‘std::vector<int

力扣报错:runtime error: reference binding to null pointer of type 'std::vector<int
在这里插入图片描述
出错原因:
有for循环或者while时,没有考虑数组为空的情况,且将判断数组为空条件写在比较靠下的位置了,比如下面时错误的:
在这里插入图片描述

解决方案:
判断数组为空条件写在最前面:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_36421001/article/details/113749195