0142. 环形链表 II #126
Replies: 1 comment
-
|
用哈希表理解起来简单粗暴一点。 class Solution:
def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]:
Ss = set()
if not head or not head.next:
return None
cur = head
while cur:
if cur in Ss:
return cur
else:
Ss.add(cur)
cur = cur.next
return None |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
0142. 环形链表 II | 算法通关手册
https://algo.itcharge.cn/solutions/0100-0199/linked-list-cycle-ii/
Beta Was this translation helpful? Give feedback.
All reactions