出错原因:

有for循环或者while时,没有考虑数组为空的情况,且将判断数组为空条件写在比较靠下的位置了,比如下面时错误的:
参考文章:
https://blog.csdn.net/qq_36421001/article/details/113749195

错误

class Solution {public:vector<int>result;vector<int> spiralOrder(vector<vector<int>>& matrix) {result.clear();int m=matrix.size();int n=matrix[0].size();if(matrix.empty())return {};int count=0;//执行出错时 是空矩阵情况,所以还要考虑一下   while(m>count*2 &&n>count*2){print(matrix,m,n,count);count++;}return result;}void print(vector<vector<int>>& matrix,int row,int col,int count){//从左到右打印一行for(int i=count,j=count;j<col-count;j++){result.push_back(matrix[count][j]);}//从上到下if(count<row-count-1){for(int i=count+1;i<row-count;i++){result.push_back(matrix[i][col-count-1]);}}//从右到左if(count<col-count-1 && count<row-count-1){for(int i=col-count-2;i>=count;i--){result.push_back(matrix[row-count-1][i]);}}//从下到上if(count<col-count-1 && count<row-count-2){for(int i=row-count-2;i>=count+1;i--){result.push_back(matrix[i][count]);;}}}
};

改成

class Solution {public:vector<int>result;vector<int> spiralOrder(vector<vector<int>>& matrix) {result.clear();if(matrix.empty())return {};int m=matrix.size();int n=matrix[0].size();int count=0;//执行出错时 是空矩阵情况,所以还要考虑一下   while(m>count*2 &&n>count*2){print(matrix,m,n,count);count++;}return result;}void print(vector<vector<int>>& matrix,int row,int col,int count){//从左到右打印一行for(int i=count,j=count;j<col-count;j++){result.push_back(matrix[count][j]);}//从上到下if(count<row-count-1){for(int i=count+1;i<row-count;i++){result.push_back(matrix[i][col-count-1]);}}//从右到左if(count<col-count-1 && count<row-count-1){for(int i=col-count-2;i>=count;i--){result.push_back(matrix[row-count-1][i]);}}//从下到上if(count<col-count-1 && count<row-count-2){for(int i=row-count-2;i>=count+1;i--){result.push_back(matrix[i][count]);;}}}
};

力扣报错:runtime error: reference binding to null pointer of type ‘std::vector<int相关推荐

  1. leetcode报错runtime error: reference binding to null pointer of type ‘std::vector<std::__cxx11::basic_

    leetcode报错:runtime error: reference binding to null pointer of type 'std::vector<std::__cxx11::ba ...

  2. LeetCode报错:Line 923: Char 9: runtime error: reference binding to null pointer of type ‘std::__cxx11:

    LeetCode报错 报错原因: Line 923: Char 9: runtime error: reference binding to null pointer of type 'std::__ ...

  3. Line 923: Char 9: runtime error: reference binding to null pointer of type ‘int‘ (stl_vector.h)

    Leetcode 报错 Line 923: Char 9: runtime error: reference binding to null pointer of type 'int' (stl_ve ...

  4. runtime error: reference binding to null pointer of type ‘int‘ (stl_vector.h)

    报错原因:没有指定数组大小 vector在还没有分配任何空间时还不能像数组一样用下标形式去访问vector的(v[0]也不行)!!!否则编译通过但报运行错误runtime error! vector是 ...

  5. LeetCode报错: “runtime error: member access within null pointer of type ‘struct ListNode”

    LeetCode里面会经常使用到ListNode这个数据结构,这个报错原因是对空指针进行了引用,但是在测试的时候并不会出现报错,只有在提交的时候才会出现报错. 两者出现区别的原因在于:在测试中给出的测 ...

  6. LeetCode报错:runtime error: member access within null pointer of type ‘struct ListNode‘

    错误题目:876. 链表的中间结点 错误原因:试图使用空指针 解决方法:找出等价判断条件进行替换,排除对空指针的引用. /*** Definition for singly-linked list.* ...

  7. runtime error: reference binding to null pointer of type ‘int‘ 问题

    这个问题我在做LeetCode的股票最大利润问题时运行遇到的,此问题为引用绑定了int类型的空指针. 根据个人遇到的情况的总结,出现这种问题的原因一般有二: 1.越界访问,查看在用下标访问vector ...

  8. 力扣报错runtime error: load of null pointer of type ‘int‘解决思路

    记录本算法小白刷力扣的这道题遇到的报错 349. 两个数组的交集https://leetcode.cn/problems/intersection-of-two-arrays/ 出现报错的代码 /** ...

  9. runtime error: member access within null pointer of type ‘struct ListNode‘错误

    LeetCode203错误分析: (3条消息) LeetCode:runtime error: member access within null pointer of type 'struct Li ...

最新文章

  1. go语言笔记——append是内置的函数!!!new是一个函数!!!调试可以使用闭包,本质上是print调试,尼玛!...
  2. python使用缩进作为语法边界一般建议怎样缩进-python基础自测挑战题,适合刚起步不久的小猿!...
  3. 2、Eternal框架-svn_有更新!
  4. Leetcode--164. 最大间距
  5. Sql Server发布订阅如何添加新表如何不初始化整个快照
  6. 用Python制作酷炫词云图,原来这么简单!
  7. 假如我来发明编程语言
  8. 2021高考成绩已出城市查询,2021年青海高考成绩什么时候出来 公布时间
  9. 38.MySQL 日志
  10. 程序设计与编译(C++入门)
  11. 44000+ 人一夜之间失业
  12. mysql5解密工具_|MSSQL数据库密码解密工具(MS SQL Server Password Unlocker)下载v4.0.0.0免费版 - 欧普软件下载...
  13. 还有3天就要上班了,面试中灵魂拷问的问题送给你
  14. 牛顿法详解(海森矩阵如何使用)
  15. 别人都不知道的“好用”网站,让你的效率飞快
  16. 基于jQuery发展历程时间轴特效代码
  17. VC6.0修改工程名字方法
  18. Microsoft Visio Professional 2013打不开也卸载不了解决办法
  19. 海航金鹿公务机队规模稳居亚太之首;奥森多生物科技创新中心在沪揭牌 | 美通企业日报...
  20. 【小蜜蜂蓝桥杯笔记】DS18B20温度传感器的使用

热门文章

  1. 无损扩展win7的c盘
  2. 视频媒体播放,最好的 HTML 解决方法
  3. 公司网站应怎样做优化标梵互动
  4. 远航CMS采集,全自动远航CMS采集插件(图文)
  5. 双非渣硕的秋招之路总结(已拿抖音研发岗SP)
  6. 如何才能确定网站设计主题
  7. ClickHouse 使用 formatDateTime() 函数 索引失效
  8. 【前端 HTML+CSS+JavaScript(JS)】DOM练习-图片在DIV间移动的实现-removeChild cloneNode position append 上下对齐 带注释/总结
  9. 一定要知道的世界奇之最(组图)
  10. 制作excel下拉菜单