package com.fishercoder.solutions;

import com.fishercoder.common.classes.ListNode;

/**
 * 876. Middle of the Linked List
 *
 * Given a non-empty, singly linked list with head node head, return a middle node of linked list.
 *
 * If there are two middle nodes, return the second middle node.
 *
 * Example 1:
 *
 * Input: [1,2,3,4,5]
 * Output: Node 3 from this list (Serialization: [3,4,5])
 * The returned node has value 3.  (The judge's serialization of this node is [3,4,5]).
 * Note that we returned a ListNode object ans, such that:
 * ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL.
 *
 *  Example 2:
 *
 * Input: [1,2,3,4,5,6]
 * Output: Node 4 from this list (Serialization: [4,5,6])
 * Since the list has two middle nodes with values 3 and 4, we return the second one.
 *
 * Note:
 *
 * The number of nodes in the given list will be between 1 and 100.
 */
public class _876 {
  public static class Solution1 {
    public ListNode middleNode(ListNode head) {
      ListNode fast = head;
      ListNode slow = head;
      while (fast != null && fast.next != null) {
        fast = fast.next.next;
        slow = slow.next;
      }
      return slow;
    }
  }
}

@@ -82,827 +82,8 @@
 e;%0A%0A
-/**%0A * 876. Middle of the Linked List%0A *%0A * Given a non-empty, singly linked list with head node head, return a middle node of linked list.%0A *%0A * If there are two middle nodes, return the second middle node.%0A *%0A * Example 1:%0A *%0A * Input: %5B1,2,3,4,5%5D%0A * Output: Node 3 from this list (Serialization: %5B3,4,5%5D)%0A * The returned node has value 3.  (The judge's serialization of this node is %5B3,4,5%5D).%0A * Note that we returned a ListNode object ans, such that:%0A * ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL.%0A *%0A *  Example 2:%0A *%0A * Input: %5B1,2,3,4,5,6%5D%0A * Output: Node 4 from this list (Serialization: %5B4,5,6%5D)%0A * Since the list has two middle nodes with values 3 and 4, we return the second one.%0A *%0A * Note:%0A *%0A * The number of nodes in the given list will be between 1 and 100.%0A */%0A
 publ
@@ -98,16 +98,18 @@
  _876 %7B%0A
+  
   public
@@ -134,24 +134,28 @@
 tion1 %7B%0A    
+  
+  
 public ListN
@@ -182,24 +182,30 @@
 ode head) %7B%0A
+      
       ListNo
@@ -216,24 +216,30 @@
 ast = head;%0A
+      
       ListNo
@@ -250,24 +250,30 @@
 low = head;%0A
+      
       while 
@@ -318,16 +318,24 @@
         
+       
+ 
 fast = f
@@ -357,16 +357,24 @@
         
+      
+  
 slow = s
@@ -389,18 +389,30 @@
 ;%0A      
+     
+ 
 %7D%0A
+      
       re
@@ -426,16 +426,22 @@
 ow;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 876