Leetcode #141 Linked List Cycle

Source: Internet
Author: User

Title Link: https://leetcode.com/problems/linked-list-cycle/

To determine if there is a ring in a list, you can set two pointers, one for each advance of the first, and two for each second.

For a forward two-pane pointer, you need to first determine if the forward one is NULL:

  • If you do not determine if it is NULL, taking two times next May cause Runtime Error.

  • If NULL, the link list does not exist in the ring.

If there is a ring in the list, then each advance of the two-cell pointer will eventually catch up with each advance of a grid of pointers.

If a ring does not exist in the list, the pointer to the two-way forward will eventually be NULL.

Note: The previous day saw the question "Judging whether there is a public part of the two linked list". One approach is to connect the two-link list to the end of the line to determine whether there is a ring problem.

Leetcode #141 Linked List Cycle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.