当前位置:网站首页>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;
}
};
边栏推荐
- Larave8 JWT API expiration custom error return
- PHP reverses scenarios based on code and skillfully uses debug_ backtrace()
- JS time conversion standard format, timestamp conversion standard format
- An error is reported when installing dataspherestudio doc: invalid default value for 'update_ time‘
- 2021-08-07 native and package types
- Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~
- @Component use cases
- Querywrapper in mybaits plus
- 1 figure to explain the difference and connection between nodejs and JS
- Complete TCP forwarding server (kernel linked list + mutex)
猜你喜欢
[email protected][])"/>NoViableAltException([email protected][])

How to realize selective screen recording for EV screen recording

Querywrapper in mybaits plus

Getting started with shell Basics

Wuenda 2022 machine learning special course evaluation is coming!
![[buuctf] [actf2020 freshman competition]include](/img/42/50439290177fdea5f431e315cac1a1.jpg)
[buuctf] [actf2020 freshman competition]include

MySQL back to table query optimization

Learn about data kinship JSON format design from sqlflow JSON format

V3 03_ Getting started

Fastcgi CGI shallow understanding
随机推荐
Larave8 JWT API expiration custom error return
Notes on reverse learning in the first week of winter vacation
org.json.JSONObject对象转json,json新增元素,根据json的key获取值。以及list对象格式字符串转jsonArray
Problem: wechat developer tool visitor mode cannot use this function
Clear the route cache in Vue
Thinkphp5 log file contains trick
Laravel artist command error
Race of golang
PHP common authentication / third-party methods
KnightCTF WEB
Mutex lock, read / write lock, spin lock, pessimistic lock, and optimistic lock
Why is the resolution of the image generated by PHP GD library 96? How to change it to 72
The difference between settimeout() and setinterval()
PHP excel export function encapsulation (based on phpexcel class)
Ctfshow getting started with the web (ThinkPHP topic)
[buuctf] [actf2020 freshman competition]exec1
Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
Error on datetime when importing SQL file from MySQL
Comprehensively analyze the basic features and summary of free and paid SSH tools
How to realize selective screen recording for EV screen recording