Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ListNode* middleNode(ListNode* head) {
- int count = 0;
- auto headp = head;
- while (head->next) {
- ++count;
- head = head->next;
- }
- int i = count % 2 ? 1 + count / 2 : count / 2;
- while(i --> 0) {
- headp = headp->next;
- }
- return headp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement