Advertisement
Kame3

FIRST_MIDDLE

Jun 10th, 2021
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. int getMiddle(Node head)
  2.     {
  3.          // Your code here.
  4.          Node p1 = head;
  5.          Node p2 = head;
  6.          
  7.          while (p2.next != null) {
  8.              p2 = p2.next;
  9.              if (p2.next != null) {
  10.                  p2 = p2.next;
  11.                  p1 = p1.next;
  12.              }
  13.          }
  14.          
  15.          return p1.data;
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement