leetcode 141 环形链表 C++
生活随笔
收集整理的這篇文章主要介紹了
leetcode 141 环形链表 C++
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
兩種方法一個空間O(n),另一個O(1),時間都是O(n)。
one
two
class Solution { public:bool hasCycle(ListNode *head) {if(!head||!head->next) return false;ListNode*slow=head,*fast=head->next;while(slow!=fast){if(!fast||!fast->next) return false;slow=slow->next;fast=fast->next->next;}return true;} };END
總結
以上是生活随笔為你收集整理的leetcode 141 环形链表 C++的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么隐藏桌面计算机名,Win7隐藏桌面所
- 下一篇: IDEA 谷歌翻译报错 TKK