Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for singly-linked list.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode() : val(0), next(nullptr) {}
- * ListNode(int x) : val(x), next(nullptr) {}
- * ListNode(int x, ListNode *next) : val(x), next(next) {}
- * };
- */
- class Solution {
- public:
- ListNode* middleNode(ListNode* head) {
- ListNode *slow, *fast;
- slow = fast = head;
- while(!(fast->next == nullptr || fast->next->next == nullptr)){
- slow = slow->next;
- fast = fast->next->next;
- }
- if(fast->next && !fast->next->next) slow = slow->next;
- return slow;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement