LeetCode算法入门- Remove Nth Node From End of List -day17
生活随笔
收集整理的這篇文章主要介紹了
LeetCode算法入门- Remove Nth Node From End of List -day17
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
LeetCode算法入門- Remove Nth Node From End of List -day17
Given a linked list, remove the n-th node from the end of list and return its head.
Example:
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the linked list becomes 1->2->3->5.
Note:
Given n will always be valid.
題意就是刪除倒數第n個節點
題意分析:使用兩個指針,一個快,一個慢,快的先走n步,當快的走到尾部null的時候,慢指針所指在就是要刪除在那個節點。
Java實現:
總結
以上是生活随笔為你收集整理的LeetCode算法入门- Remove Nth Node From End of List -day17的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一篇文章读懂MySQL的各种联合查询
- 下一篇: 插入排序--~