Symmetric Tree @ LeetCode (Python)
Surrounded Regions @ LeetCode (Python)

Linked List Cycle @ LeetCode (Python)

kitt posted @ 2014年2月22日 21:53 in LeetCode , 2153 阅读

使用一个快指针和一个慢指针遍历,如果两者相遇说明有环。

# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    # @param head, a ListNode
    # @return a boolean
    def hasCycle(self, head):
        fastP = slowP = head
        while fastP != None and fastP.next != None:
            fastP = fastP.next.next
            slowP = slowP.next
            if fastP == slowP: return True
        return False
Avatar_small
AP 10th General Scie 说:
2022年9月17日 13:15

All Andhra Pradesh State Class 10th (SSC) Students can download AP SSC Science model paper 2023 with Answer solutions in Chapter by Chapter for Physical Science, Chemistry, Biological Science and Environmental science for AP SSC Science Model Paper 2023 examination test for Unit Test-1, Unit Test-2, AP 10th General Science Question Paper Unit Test-3, Unit Test-4, and Quarterly, Half Yearly, Pre-Final with Annual final examination tests 2023. The Andhra Pradesh State Board of Secondary Education has published the General Science model paper with study material with practice paper with mock test question bank as AP 10th Biology, PS, Chemistry Model Paper 2023 for all examination tests conducted by BSEAP.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter