— Diary, Programming — 1 min read
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.
1bool hasCycle(ListNode *head) {2 if (!head) return false;34 ListNode *fast = head->next;56 while ((head != NULL) && (fast != NULL) && (fast->next != NULL)) {7 if (head == fast) return true;8 head = head->next;9 fast = fast->next->next;10 }1112 return false;13}
Time complexity O(n)
, space O(1)
That's enough for today. Will be back when I'm better.
Goodbye