knakul853

Untitled

Jul 16th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. /**
  2. knakul853
  3.  */
  4. class Solution {
  5. public:
  6.     ListNode* middleNode(ListNode* head) {
  7.         int cnt = 0;
  8.         ListNode*cur = head;
  9.         while(cur)
  10.         {
  11.             cur = cur->next;
  12.             cnt++;
  13.         }
  14.        cnt/=2;
  15.         while(cnt)
  16.         {
  17.             head = head->next;
  18.             cnt--;
  19.         }
  20.        
  21.         return head;
  22.     }
  23. };
Add Comment
Please, Sign In to add comment