当前位置:网站首页>Double pointer circular linked list
Double pointer circular linked list
2022-06-30 14:37:00 【Douglas_ LT】
A daily topic ing, Today is a day medium topic 142. Linked List Cycle II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
class Solution {
public:
ListNode *detectCycle(ListNode *head) {
ListNode *fast=head,*slow=head;
do{
if(!fast||!fast->next)
return nullptr;
slow=slow->next;
fast=fast->next->next;
}while(fast!=slow);
fast=head;
while(fast!=slow){
fast=fast->next;
slow=slow->next;
}
return fast;
}
};
边栏推荐
- Initial attack and defense world Misc
- 从控制层返回到js的json数据带“\”转译符,怎么去掉
- DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
- The first three passes of sqli Labs
- PHP conditional operator
- ot initialized – call ‘refresh’ before invoking lifecycle methods via the context: Root WebApplicati
- Mutex lock, read / write lock, spin lock, pessimistic lock, and optimistic lock
- JS array
- Error on datetime when importing SQL file from MySQL
- V3 03_ Getting started
猜你喜欢

Ctfshow getting started with the web (ThinkPHP topic)

Crypto questions

Race of golang
![[buuctf] [geek challenge 2019] secret file](/img/00/23bebd013eb4035555c0057725e3c4.jpg)
[buuctf] [geek challenge 2019] secret file

Geoffreyhinton: my 50 years of in-depth study and Research on mental skills

Detailed explanation of the first three passes of upload Labs

Jetpack compose for perfect screen fit

Error on datetime when importing SQL file from MySQL

Realize a simple LAN communication (similar to feiqiu)

Shell programming overview
随机推荐
@component使用案例
PHP multidimensional array sorting
Implement a long-click list pop-up box on apiccloud
Zend studio how to import an existing project
PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available
How to use Alibaba Vector Icon
Chapter 13 signal (III) - example demonstration
ThinkPHP show method parameter controllable command execution
For loop and promise to solve the problem of concurrent callback
Error on datetime when importing SQL file from MySQL
Shell programming overview
On simple code crawling Youdao translation_ 0's problem (to be solved)
Laravel artist command error
Effect of shadow around the block after mouse over
Upgrade centos7 mysql5.5 to mysql5.7 non RPM in the form of tar package
ES6 notes
Calculates the length of the last word in a string, separated by spaces
ot initialized – call ‘refresh’ before invoking lifecycle methods via the context: Root WebApplicati
Problems in QT creator (additional unknown and error lines are listed in the debug output window)
Impersonate server and client using message queuing