Middle of the Linked List problem results
First Blood
Saving each node in a vector, calculate the middle index, and get the node in the vector.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
ListNode* middleNode(ListNode* head) {
vector<ListNode*> node_list;
node_list.push_back(head);
while(head->next != nullptr)
{
head = head->next;
node_list.push_back(head);
}
int index = node_list.size()/2;
return node_list[index];
}
}