Leetcode 报错
Line 923: Char 9: runtime error: reference binding to null pointer of type ‘int’ (stl_vector.h)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/…/lib/gcc/x86_64-linux-gnu/8/…/…/…/…/include/c++/8/bits/stl_vector.h:933:9
输入为空时的判断
如下的判断是错误的,不知道为什么。
int numIslands(vector<vector<char>>& grid) {int m=grid.size();int n=grid[0].size();if(n==0|| m==0) return 0;
使用下面的判断通过
int numIslands(vector<vector<char>>& grid) {if(grid.size()==0 ) return 0;int m=grid.size();int n=grid[0].size();