Find the middle of a given linked list Solution - java
For Explanation watch video:
Code::
Function to find Middle element if Head Of Linked List Given
class Solution
{
int getMiddle(Node head)
{
Node slow = head;
Node fast = head;
while(fast!=null && fast.next!=null){
slow = slow.next;
fast = fast.next.next;
}
return slow.data;
}
}
Comments
Post a Comment