Website Summary Files Commits Branches @commit @diff @stats
path: root / Practicum / pract05 / solutions / Task02.cpp
blob: 4905d58b837be887b72163430526bcad1a812810 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
    ListNode* middleNode(ListNode* head) {
        if(!head)
            return nullptr;
      
        ListNode* middle = head;
        ListNode* end = head;

        while(end != nullptr && end->next != nullptr) {
            middle = middle->next;
            end = end->next->next;
        }
        return middle;        
    }
};