When a body of mass M is made to undergo a freefall, from a height H, the distance(s) travelled by it is given by
$$s=H-ut-\frac{1}{2}gt^{2}$$
$$\begin{align*}&\text{Where,}\\
&H~\text{is the height from which it is dropped,}\\
&u~\text{is the initial speed and}\\
&g~\text{is acceleration due to gravity.}
\end{align*}$$
By considering H as the origin with downward direction + and initial speed zero, the equation reduces to
$$s=\frac{1}{2}gt^2$$
g can be measured by measuring the time required (t) by the body to travel a fixed distance (d) from the origin
$$g=\frac{2d}{t^2}$$
To make the measurement independent of the initial time, i.e. t=0, the time required to travel two distances (d1 & d2) as t1 and t2 can be used.
$$g=\frac{2(d_2-d_1)}{{(t_2-t_1)}^2}$$