Solution (source code)

= Solution

The process is adapted to its <natural filtration>. At each fixed time it has finite support and is therefore integrable. Conditional on $X_{n-1}=0$,
$$
\mathbb E[X_n\mid X_{n-1}=0]
=\frac1{2n}-\frac1{2n}=0=X_{n-1}.
$$
Conditional on $X_{n-1}\ne0$,
$$
\mathbb E[X_n\mid X_{n-1}]
=\frac1n(nX_{n-1})+\left(1-\frac1n\right)0
=X_{n-1}.
$$
The <Markov property> now gives
$$
\mathbb E[X_n\mid\mathcal F_{n-1}]
=\mathbb E[X_n\mid X_{n-1}]=X_{n-1},
$$
so $(X_n)$ is a <martingale>.