Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

剑指 Offer 18. 删除链表的节点 #17

Open
GpingFeng opened this issue Dec 22, 2020 · 0 comments
Open

剑指 Offer 18. 删除链表的节点 #17

GpingFeng opened this issue Dec 22, 2020 · 0 comments

Comments

@GpingFeng
Copy link
Owner

剑指 Offer 18. 删除链表的节点

思路

要删除单链表中一个节点,分为以下几个步骤

  • 特殊情况,等于 head 的值时,直接返回
  • 使用 prev 存放前一个值,cur 存放当前遍历到的值
  • 遍历查找到该节点
  • 将该节点的前一个节点直接指向该节点的后一个节点
  • 返回 head

注意点

  • 需要注意特殊情况,当删除的节点是 head 的时候,则直接返回 head.next 即可

复杂度分析

  • 时间复杂度O(n)
  • 空间复杂度O(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant