Example 14 A permutation $\left\{a_{1}, a_{2}, \cdots, a_{n}\right\}$ of the set $\{1,2, \cdots, n\}$ is called a derangement (or wrong permutation) if $a_{i} \neq i$ $(i=1,2, \cdots, n)$. Find the number of derangements $D_{n}$.
It is known that $D_{1}=0, D_{2}=1$.
For $n \geqslant 3$ and any derangement $\left\{a_{1}, a_{2}, \cdots, a_{n}\right\}$ of $\{1,2, \cdots, n\}$, $a_{1}$ can take any of the other $n-1$ numbers except 1. Let $a_{1}=k(k \neq 1)$, then
(1) If $a_{k}=1$, the number of such derangements is the number of derangements of $n-2$ elements, so there are $D_{n-2}$;
(2) If $a_{k} \neq 1$, then this derangement is a permutation of the elements $1,2, \cdots, k-1, k+1, \cdots, n$ in the 2nd to the $n$th positions, where 1 is not in the $k$th position, and the other elements are not in their own positions. This permutation is equivalent to a derangement of the $n-1$ elements 2,3, $\cdots, n$, so there are $D_{n-1}$.
Thus, we have
$$
D_{n}=(n-1)\left(D_{n-1}+D_{n-2}\right) \cdot(n \geqslant 3)
$$

Let $E_{n}=\frac{D_{n}}{n!}$, then (1) can be transformed into
$$
E_{n}=\left(1-\frac{1}{n}\right) E_{n-1}+\frac{1}{n} E_{n-2},
$$

Therefore,
$$
E_{n}-E_{n-1}=\left(-\frac{1}{n}\right)\left(E_{n-1}-E_{n-2}\right),
$$

Repeatedly using (2), and noting that $E_{1}=0, E_{2}=\frac{1}{2}$, for $n \geqslant 2$, we have
$$
\begin{aligned}
E_{n}-E_{n-1} & =\left(-\frac{1}{n}\right)\left(-\frac{1}{n-1}\right)\left(E_{n-2}-E_{n-3}\right)=\cdots \\
& =\left(-\frac{1}{n}\right)\left(-\frac{1}{n-1}\right) \cdots\left(-\frac{1}{3}\right)\left(E_{2}-E_{1}\right) \\
& =\frac{(-1)^{n}}{n!} .
\end{aligned}
$$

From this, we get $E_{n}=\frac{(-1)^{n}}{n!}+\frac{(-1)^{n-1}}{(n-1)!}+\cdots+\frac{(-1)^{2}}{2!}$,
so $D_{n}=n!\left(1-\frac{1}{1!}+\frac{1}{2!}-\cdots+(-1)^{n} \frac{1}{n!}\right)$.