I somehow not sure what is wrong with call to insert for the object "history" where history is of type map. I have checked that there should be an insert function for a map object where the insert function would take in a pair as an argument. However I keep getting the error of
#include <map>
using namespace std;
class Solution {
public:
ListNode *detectCycle(ListNode *head) {
std::map<ListNode, int> history; \\ so here history is created to be an object of type map
ListNode *current = head;
if(head == NULL) {
return nullptr;
} else {
while(current->next) {
history.insert(make_pair(current, current->val)); \\ this line has the error of no matching member function for call to "insert"
if(history.count(current->next)) {
return current->next;
}
}
}
return nullptr;
}
};
could someone points out what is wrong here? or maybe my understanding in the c++ map class?
sorry I am pretty new to c++ and my uses of c++ terminology might not even be right.
thank you