Middle of the Linked List 0ms (100 % Faster)

class Solution {
public ListNode middleNode(ListNode head) {
ListNode temp = head;
int size=0;

   int count=0;
    
    while(temp !=null){
        size++;
        temp=temp.next;
    }
    temp=head;

    while(temp !=null){
        if(count==(size/2)){
          break;
       
    }
        count++;
        temp=temp.next;
  
}
    return temp;

}
}

Comments (0)