π Problem Details Title: 141. Linked List Cycle Link: https://leetcode.com/problems/linked-list-cycle/ Difficulty: Easy Tags/Categories: Linked-List Hashmap πWhat Were My Initial Thoughts? - iterate through the list - insert each node into the set - before inserting, check if the node already exists in the set - if it does return false, otherwise continue π€What Did I Struggle With? ~ π‘ Explanation of Solution same as intuition β Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) π» Implementation of Solution class Solution { public: bool hasCycle(ListNode *head) { unordered_set<ListNode*> set; ListNode* curr = head; while(curr != nullptr) { if(set.find(curr) != set.end()) { return true; } else { set.insert(curr); curr = curr->next; } } return false; } };