Example 10 Let $x_{1}, x_{2}, \cdots, x_{n}$ be any permutation of $1,2, \cdots, n$. Find
$$
u=\left|x_{1}-1\right|+\left|x_{2}-2\right|+\cdots+\left|x_{n}-n\right|
$$
the maximum value.
(1) If $n=2 k$ (where $k$ is a positive integer), then
$$
\begin{array}{l}
u_{\text {max }}=[n+n+\cdots+(k+1)+(k+1)]- \\
\quad(k+k+\cdots+1+1) \\
=2(1+2+\cdots+n)-4(1+2+\cdots+k) \\
=n(n+1)-2 k(k+1)=\frac{1}{2} n^{2} .
\end{array}
$$
(2) If $n=2 k+1$ (where $k$ is a positive integer), then
$$
\begin{array}{l}
u_{\text {max }}=[n+n+\cdots+(k+2)+(k+2)+(k+1)]- \\
{[(k+1)+k+k+\cdots+1+1]} \\
=2(1+2+\cdots+n)- \\
4(1+2+\cdots+k)-2(k+1) \\
=n(n+1)-2 k(k+1)-2(k+1) \\
=\frac{1}{2}\left(n^{2}-1\right) \text {. } \\
\end{array}
$$