목록Algorithm/Two-Pointers (1)
5 DERECHA
142. Linked List Cycle II ( Hash / Tortoise & hash Algorithms )
1) using unordered_map Time Complexity : O(n) class Solution { public: ListNode *detectCycle(ListNode *ptr) { unordered_map hash; while(hash[ptr]==0){ if(ptr==NULL) return NULL; hash[ptr]=1; ptr = ptr->next; } return ptr; } }; 2) using unoredered_set Time Complexity : O(n) class Solution { public: ListNode *detectCycle(ListNode *ptr) { unordered_set hash; while(hash.count(ptr)==0){ if(ptr == NUL..
Algorithm/Two-Pointers
2023. 3. 9. 19:34