Skip to content
Paras Gupta

Feb 3 - Daily Programming Diary

Diary, Programming1 min read

15:00

Not feeling so good so I'll just be doing today's Leetcode challenge. Question is easy and I've done it before so it probably won't be difficult.

linked-list-cycle.cpp
1bool hasCycle(ListNode *head) {
2 if (!head) return false;
3
4 ListNode *fast = head->next;
5
6 while ((head != NULL) && (fast != NULL) && (fast->next != NULL)) {
7 if (head == fast) return true;
8 head = head->next;
9 fast = fast->next->next;
10 }
11
12 return false;
13}

Time complexity O(n), space O(1)

That's enough for today. Will be back when I'm better.

Goodbye

EOD Checklist

  • Leetcode February Challenge
  • This blog
© 2022 by Paras Gupta. All rights reserved.
Theme by LekoArts