摘要: 递归初步见: https://www.cnblogs.com/San-Francisco/p/14882647.html 题目: https://leetcode-cn.com/problems/swap-nodes-in-pairs/ 两两交换链表中的结点,分别用了1.递归 2.迭代 两个方法解决 阅读全文
posted @ 2021-06-15 15:19 SanFranciscoo 阅读(33) 评论(0) 推荐(0) 编辑
摘要: 题目链接如下: https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/ 本题使用了如下两个方法: 哑结点:若给定的链表中没有空的头节点,设置一个哑结点在第一个结点前面,最后在删除掉。 如: 题目中给定 head 作为链表的 阅读全文
posted @ 2021-06-15 13:49 SanFranciscoo 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 空指针引用问题,最近经常遇到这个bug,找出了出现此bug的一个原因: 不能引用没有被赋值的指针。 例如: int *q=p->next; 要改为: if(p){ int *q=p->next; } 要使用指针p,必须保证p不为空指针。 更具体地,再举一个例子: #include <iostream 阅读全文
posted @ 2021-06-15 13:19 SanFranciscoo 阅读(692) 评论(0) 推荐(0) 编辑
摘要: 递归初步学习参考了以下博客: https://lyl0724.github.io/2020/01/25/1/ 本题: https://leetcode-cn.com/problems/merge-two-sorted-lists/ 方法一:哑结点,暴力 设一个哑结点为合并后链表的暂时头节点,待两个链 阅读全文
posted @ 2021-06-15 12:36 SanFranciscoo 阅读(53) 评论(0) 推荐(0) 编辑