public int medium() {
Node slowPtr = head;
Node fastPtr = head;
Node preSlow = head;
if (head != null)
{
while (fastPtr != null && fastPtr.next != null)
{
fastPtr = fastPtr.next.next;
preSlow = slowPtr;
slowPtr = slowPtr.next;
}
if (fastPtr != null)
{
return slowPtr.value;
}
else
{
return (slowPtr.value + preSlow.value) / 2;
}
}
return 0;
}
1m58s Goto Github PK
Name: Dai Qianqian (戴茜茜)
Type: User
Company: University of Leeds
Bio: git submodule update --recursive --progress --init
Location: Leeds, UK