s0142
This commit is contained in:
24
include/s0142_linked_list_cycle.hpp
Normal file
24
include/s0142_linked_list_cycle.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef S0142_LINKED_LIST_CYCLE_HPP
|
||||
#define S0142_LINKED_LIST_CYCLE_HPP
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
struct ListNode {
|
||||
int val;
|
||||
ListNode* next;
|
||||
ListNode(int x) : val(x), next(nullptr) {}
|
||||
};
|
||||
|
||||
struct IterResult {
|
||||
ListNode *node;
|
||||
bool meet;
|
||||
};
|
||||
|
||||
class S0142 {
|
||||
public:
|
||||
std::unordered_map<ListNode *, int> footprint;
|
||||
IterResult iter(ListNode *fast, ListNode* slow, bool startUp);
|
||||
ListNode *detectCycle(ListNode *head);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user