Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. ListNode* middleNode(ListNode* head) {
  2.         int count = 0;
  3.         auto headp = head;
  4.         while (head->next) {
  5.             ++count;
  6.             head = head->next;
  7.         }
  8.         int i = count % 2 ? 1 + count / 2 : count / 2;
  9.         while(i --> 0) {
  10.             headp = headp->next;
  11.         }
  12.         return headp;
  13.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement