LeetCode 876. 链表的中间结点
生活随笔
收集整理的這篇文章主要介紹了
LeetCode 876. 链表的中间结点
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原題鏈接
解題思路:快慢指針,快指針走兩步,慢指針走一步??熘羔樀絅ULL慢指針自然到中間位置
/*** Definition for singly-linked list.* struct ListNode {* int val;* ListNode *next;* ListNode(int x) : val(x), next(NULL) {}* };*/ class Solution { public:ListNode* middleNode(ListNode* head) {ListNode* p=head;ListNode* q=head;while(q&&q->next){p=p->next;q=q->next->next;}return p;} };?
總結
以上是生活随笔為你收集整理的LeetCode 876. 链表的中间结点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 建行开户可以代办吗?
- 下一篇: LeetCode 面试题 链表中倒数