'NoneType' object has no attribute 'val'
时间: 2023-08-20 20:06:46 浏览: 64
这个错误出现在对一个'NoneType'对象使用.val属性时。这种错误常见于二叉树或链表的操作中。在刷二叉树或树类型的题目时,这个错误通常出现在叶子节点的临界值位置。如果left或right为None时,就会出现这个错误。要解决这个问题,可以在使用.val属性之前先判断left和right是否为None,如果是则返回False。另一个例子是在获取整个链表所有val的时候,可以使用while循环来遍历链表,但在使用.cur.val之前,需要先判断.cur是否为None。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [‘NoneType‘ object has no attribute ‘val‘类型错误分析](https://blog.csdn.net/qq_48915178/article/details/121869467)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [解决AttributeError: ‘NoneType‘ object has no attribute ‘val‘ if left.val!=right.val:Line 17 问题](https://blog.csdn.net/zhangkai__/article/details/125491759)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文