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