leetcode 编译问题:Line x: member access within null pointer of type 'struct TreeNode'


参考:

LEETCODE 中的member access within null pointer of type 'struct ListNode'

解决 leetcode 编译问题:Line x: member access within null pointer of type 'struct TreeNode'

在leetcode上提交代码后出现编译错误:

Line x: member access within null pointer of type 'struct TreeNode'

原因:在测试过程中,第x行访问的指针为NULL,通常情况下表明程序未对NULL情况作出判断。例如:

int val = root->next->val;

在这一行中,没有加入rootroot->next是否为空的判断,因此需修改为:

if (root != NULL) {
    if (root->next != NULL) {
        int val = root->next->val;
    }
}

2018.7


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM