Leetcode (Linked list pattern)

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/3

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:37 PM on 9/17/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

4 Terms

1
New cards

141. Linked List Cycle

2 ways to approach this problem

  • Keep track of all nodes you have visited in a HashSet. If you notice that you have already visited a given node, return true. This solution takes O (n) space and O (n) time. If the iterator reaches null, there is no cycle.

  • Take a fast pointer and a slow pointer. Fast pointer moves twice as fast as the slow pointer. If the fast pointer reaches end, there is no cycle. If at any given point the fast pointer and slow pointer are the same node element, return truel. This solution takes O (1) space and O (n) time.

2
New cards

876. Middle of the Linked List

  • Use two pointers, both initially pointing to head

  • One moves twice as fast as the other

  • When the fast one reaches the end of the linked list, the slower one will reach the middle

  • Time : O (n), Space: O (1)

3
New cards

1

2

4
New cards

2

14