leetcode,剑指offer 31题报错:

Line 170: Char 16: runtime error: reference binding to misaligned address 0xbebebebebebec0ba for type 'int', which requires 4 byte alignment (stl_deque.h) 0xbebebebebebec0ba: note: pointer points here <memory cannot be printed> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:180:16

代码:

class Solution {
public:bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {stack<int> stk;int i = 1, j = 0, n = pushed.size();// if(n == 0)if(n == 0 || (n == 1 && pushed[0] == popped[0])){return true;}stk.push(pushed[0]);while(i < n){while(i<n && stk.top() != popped[j]){stk.push(pushed[i]);++i;}while(!stk.empty() && stk.top() == popped[j]){stk.pop();j++;}}return stk.empty();}
};

原因:

网上查是数组越界问题,经检查程序验证:

为非法访问地址,不只是数组越界本程序报错原因为:

栈stack<int> stk;为空时访问了stk.top()。

解决办法:

stk.top()前加一个栈空判断即可,即stk.empty() && stk.top();

改正后代码:

class Solution {
public:bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {stack<int> stk;int i = 1, j = 0, n = pushed.size();if(n == 0 || (n == 1 && pushed[0] == popped[0])){return true;}stk.push(pushed[0]);while(i < n){while(i < n && (stk.empty() || stk.top() != popped[j])){stk.push(pushed[i]);++i;}while(!stk.empty() && stk.top() == popped[j]){stk.pop();j++;}}return stk.empty();}
};

leetcode报错:reference binding to misaligned address 0xbebebebebebec0ba for type ‘int‘, which requir 4相关推荐

  1. leetcode报错:member access within null pointer of type struct ListNode

    leetcode报错:member access within null pointer of type 'struct ListNode'

  2. LeetCode 报错AddressSanitizer: SEGV on unknown address 0x000000619d20 (pc 0x000000401a6a bp 0x7ffd35b3

    LeetCode90子集 II 题目描述: 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: [ ...

  3. 【leetcode报错】AddressSanitizer: heap-buffer-overflow on address 0x6020000000a0 at pc 0x00000034b4d9 bp

    原题是力扣第一道题[两数之和] 我的解题代码,报错了,解决方案写在注释里了: class Solution {public:vector<int> twoSum(vector<int ...

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

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

  5. LeetCode 报错AddressSanitizer: SEGV on unknown address (pc 0x0000003445e3 bp 0x7ffdb86b99e0 sp 0x7ffdb

    这种错误就是数组越界了. 我这里例子里即使递归结束了,没有直接return,结果计算row和col的时候就越界了.,要把return :取消注释

  6. 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 ...

  7. 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::__ ...

  8. LeetCode 报错解决 heap-buffer-overflow Heap-use-after-free Stack-buffer-overflow Global-buffer-overflow

    文章目录 前言 Heap-buffer-overflow Heap-use-after-free Stack-buffer-overflow Global-buffer-overflow 前言 在做L ...

  9. nginx 报错 99: Cannot assign requested address

    为什么80%的码农都做不了架构师?>>>    nginx 报错 99: Cannot assign requested address net.ipv4.ip_local_port ...

最新文章

  1. 面试官问你想找什么工作_找工作时如何面试面试官
  2. 论电子计算机在审计中的应用,计算机技术在审计中的应用领域分析.doc
  3. mysql全表扫描和用索引的区别
  4. Rest风格的URL地址约束||高版本Tomcat;Rest支持有点问题
  5. oracle 怎么调整emctl,emca和emctl的日常用法及实例(经验保存)
  6. 每天学点Shiro-集成spring
  7. koa2异常处理_koa2 中的错误处理以及中间件设计原理
  8. 算法题:I am a student. 转为 student. a am I
  9. Linux系统下载镜像
  10. ADC 前端电路的五个设计步骤(转载)
  11. 计算机专业研究生读研规划,关于一个计算机研究生人生规划的迷惑
  12. RGB,CMYK,HSB,LAB颜色空间定义
  13. matlab打开界面模糊,matlab模糊逻辑(一)
  14. Android批量添加联系人到通讯录
  15. 超神,chatexcel快速制作任意excel表格,给出指令即可
  16. oracle语句怎么查工作日,SQL查询工作日 - Oracle开发 - ITPUB论坛-中国专业的IT技术社区...
  17. 最短路 dij floy spfa
  18. karas报错filename = 'fine_tuned_net.h5', file descriptor = 24, errno = 28, error message = 'No space l
  19. 【帅琪达】git相关面试题目
  20. 艾永亮:超级产品战略实现企业超级增长,五个案例给出最佳答案!

热门文章

  1. electron在线升级更新的两种方式(整体更新和部分更新)及我是如何实现electron在线升级热更新功能的?(企业级项目已上线)
  2. 这些电脑软件堪称惊艳,你一定用得上【建议收藏】
  3. 金融数据类——美国对冲基金持仓
  4. 急!急!急!如何申请公网ip
  5. 【bzoj2121】字符串游戏 【动态规划dp】
  6. mysql js 命令行登录_MYSQL常用命令
  7. 飞蛾投火式的瞬间灿烂
  8. Android开发本地及网络Mp3音乐播放器(十)最近播放界面与数据保存更新
  9. Python 日期时间格式化输出,带年、月、日、时、分、秒
  10. 吊打面试官系列之:掌握兼容性测试21个知识点,让面试官也对你膜拜。