草庐IT

runtime error: member access within null pointer of type ‘TreeNode‘ (solution.cpp)

编程小白好好干 2023-10-22 原文

在做Leetcode题的时候,我做到了一个关于对称二叉树题目,题目如下:

经过编译得出的结果如下:

第14行代码发生了报错

经过我的查找资料和修改发现,在某行访问的指针为空的时候,通常情况下表明程序未对NULL情况做出判断,因此程序出现运行错误。修改如下:

class Solution {

public:

    bool isMirror(TreeNode*p,TreeNode*q){

        if(!p&&!q){return true;}

        if(!p||!q||p->val!=q->val) {return false;}

        return (isMirror(p->left,q->right)&&isMirror(p->right,q->left));

    }

    bool isSymmetric(TreeNode* root) {

        if(!root) return true;

        return (isMirror(root->left,root->right));

    }

};

 

有关runtime error: member access within null pointer of type ‘TreeNode‘ (solution.cpp)的更多相关文章

  1. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  2. 【RuntimeError: CUDA error: device-side assert triggered】问题与解决 - 2

    RuntimeError:CUDAerror:device-sideasserttriggered问题描述解决思路发现问题:总结问题描述当我在调试模型的时候,出现了如下的问题/opt/conda/conda-bld/pytorch_1656352465323/work/aten/src/ATen/native/cuda/IndexKernel.cu:91:operator():block:[5,0,0],thread:[63,0,0]Assertion`index>=-sizes[i]&&index通过提示信息可以知道是个数组越界的问题。但是如图一中第二行话所说这个问题可能并不出在提示的代码段

  3. ruby - Tcl 是否具有 PE​​RL 和 Ruby backtic 的等价物 - 2

    在Ruby/PERL中,我可以很容易地将系统命令的控制台输出输入到一个文件中。例如:$k=`ls`将ls的输出输入到PERL(和Ruby)中的变量$k。如何在Tcl中做这样的事情?谢谢 最佳答案 使用exec命令得到相同的。setoutput[execls]puts$output手册页:exec 关于ruby-Tcl是否具有PE​​RL和Rubybacktic的等价物,我们在StackOverflow上找到一个类似的问题: https://stackoverf

  4. ruby - 通过 gem install mechanize 安装 gems 时显示错误 "invalid switch in RUBYOPT: -F (RuntimeError)" - 2

    我尝试通过以下命令在我的计算机上安装gem(Mechanize):>>geminstallmechanize--platform=ruby>>geminstallmechanize错误ERROR:Errorinstallingmechanize:ERROR:Failedtobuildgemnativeextension."C:/ProgramFiles/Ruby200-x64/bin/ruby.exe"extconf.rbC:/ProgramFiles/Ruby200-x64/bin/ruby.exe:invalidswitchinRUBYOPT:-F(RuntimeError)在我尝

  5. ruby-on-rails - RunTimeError:Rspec 2.10.1 中的 ActionController::RackDelegation for rails 3.1.4 应用程序 Controller - 2

    在我们的rails3.1.4应用程序中,rspec用于测试应用程序Controller中的公共(public)方法require_signin。这是require_signin方法:defrequire_signinif!signed_in?flash.now.alert="Loginfirst!"redirect_tosignin_pathendend这是rspec代码:it"shouldinvokerequire_signinforthosewithoutlogin"docontroller.send(:require_signin)controller{shouldredirec

  6. ruby-on-rails - rails : wkhtmltopdf RuntimeError (Location of wkhtmltopdf unknown) - 2

    我正在使用Ubuntu11.04在RubyonRails中开发一个应用程序。在应用程序中,我需要生成pdf文档。所以我正在使用wicked_pdf和wkhtmltopdf二进制gem。在我系统的开发环境中,一切正常。但是一旦我使用Phusion在CentOS5.6上部署应用程序乘客,当我尝试动态生成pdf时,出现以下错误:RuntimeError(wkhtmltopdf位置未知)我正在使用Ruby1.9.2.p136rails3.1.1任何帮助将不胜感激......谢谢。 最佳答案 另一种方法是通过Gemfile安装二进制文件。只需

  7. ruby - Rails 5 升级:在 ActionDispatch::ParamsParser (RuntimeError) 之后没有要插入的中间件 - 2

    我正在将开发中的应用程序从Rails4.2升级到Rails5beta1.1。应用程序在升级前运行良好。我已经完成了基本的升级步骤(更新Ruby、更新Rails和相关步骤:http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html)。Gemfile也已更新为最新的Gems。当我运行$railsmiddleware或$railsconsole或$railsserver时,出现以下错误:Nosuchmiddlewaretoinsertafter:ActionDispatch::ParamsParser.../.rvm/gems

  8. ruby - bundle exec rspec spec/=> RUBYOPT : -F (RuntimeError) 中的无效开关 - 2

    当我在Windows764位系统上运行bundleexecrspecspec/时,我收到以下错误:invalidswitchinRUBYOPT:-F(RuntimeError)我正在运行ruby​​1.9.2p136(2010-12-25)[i386-mingw32](安装在c:\ProgramFiles(x86)\Ruby192)和bundler1.0.15(作为ruby​​gem安装).关于如何解决这个问题的任何线索?谢谢,本 最佳答案 Bundler不喜欢Ruby的路径包含空格这一事实。为了解决这个问题,我编辑了runtime

  9. ruby-on-rails - REXML::RuntimeError(实体扩展变得太大) - 2

    今天升级到Ruby-1.9.3-p392后,REXML在尝试检索超过一定大小的XML响应时抛出运行时错误-一切正常,当接收到25条以下的XML记录时不会抛出错误,但是一旦达到特定的XML响应长度阈值,我收到此错误:Erroroccurredwhileparsingrequestparameters.Contents:RuntimeError(entityexpansionhasgrowntoolarge):/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/text.rb:387:in`blockinunnormalize'我意识到这在最

  10. ruby - 背包 : how to add item type to existing solution - 2

    我一直在使用动态规划的这种变体来解决背包问题:KnapsackItem=Struct.new(:name,:cost,:value)KnapsackProblem=Struct.new(:items,:max_cost)defdynamic_programming_knapsack(problem)num_items=problem.items.sizeitems=problem.itemsmax_cost=problem.max_costcost_matrix=zeros(num_items,max_cost+1)num_items.timesdo|i|(max_cost+1).ti

随机推荐