Let $N:=A-B$. By assumption, the matrix $N$ is nilpotent.
This means that there exists a positive integer $n$ such that $N^n$ is the zero matrix $O$.

Let $\lambda$ be an eigenvalue of $B$ and let $\mathbf{v}$ be an eigenvector corresponding to $\lambda$. That is, we have $B\mathbf{v}=\lambda \mathbf{v}$ and $\mathbf{v}\neq \mathbf{0}$.
We prove that $\lambda$ is also an eigenvalue of $A$.

Note that since $A$ and $B$ commute each other, it follows that the matrices $N$ and $B-\lambda I$ commute each other as well.
Then we compute
\begin{align*}
(A-\lambda I)^n&=(N+B-\lambda I)^n\\
&=\sum_{i=0}^n \begin{pmatrix}
n \\
i
\end{pmatrix}
N^i(B-\lambda I)^{n-i},
\end{align*}
where the second equality follows by the binomial expansion. (Note that the binomial expansion is true for matrices commuting each other.)
Then we have
\begin{align*}
(A-\lambda I)^n \mathbf{v}&=\sum_{i=0}^{n-1} \begin{pmatrix}
n \\
i
\end{pmatrix}
N^i(B-\lambda I)^{n-i}\mathbf{v}+N^n\mathbf{v}=\mathbf{0}
\end{align*}
since $(B-\lambda I)\mathbf{v}=\mathbf{0}$ and $N^n=O$.

This implies that there exists an integer $k$, $0\leq k \leq n-1$ such that
\[\mathbf{u}:=(A-\lambda I)^k\mathbf{v}\neq \mathbf{0} \text{ and } (A-\lambda I)^{k+1}\mathbf{v}=\mathbf{0}.\]

It yields that $(A-\lambda I)\mathbf{u}=\mathbf{0}$ and $\mathbf{u}\neq \mathbf{0}$, or equivalently $A\mathbf{u}=\lambda \mathbf{u}$.
Hence $\lambda$ is an eigenvalue of $A$.

This proves that each eigenvalue of $B$ is an eigenvalue of $A$.
Note that if $A-B$ is nilpotent, then $B-A$ is also nilpotent.
Thus, switching the roles of $A$ and $B$, we also see that each eigenvalue of $A$ is an eigenvalue of $B$.
Therefore, the eigenvalues of $A$ and $B$ are the same.

An Example of a Matrix that Cannot Be a Commutator
Let $I$ be the $2\times 2$ identity matrix.
Then prove that $-I$ cannot be a commutator $[A, B]:=ABA^{-1}B^{-1}$ for any $2\times 2$ matrices $A$ and $B$ with determinant $1$.
Proof.
Assume that $[A, B]=-I$. Then $ABA^{-1}B^{-1}=-I$ implies
\[ABA^{-1}=-B. […]

Nilpotent Matrices and Non-Singularity of Such Matrices
Let $A$ be an $n \times n$ nilpotent matrix, that is, $A^m=O$ for some positive integer $m$, where $O$ is the $n \times n$ zero matrix.
Prove that $A$ is a singular matrix and also prove that $I-A, I+A$ are both nonsingular matrices, where $I$ is the $n\times n$ identity […]

Nilpotent Matrix and Eigenvalues of the Matrix
An $n\times n$ matrix $A$ is called nilpotent if $A^k=O$, where $O$ is the $n\times n$ zero matrix.
Prove the followings.
(a) The matrix $A$ is nilpotent if and only if all the eigenvalues of $A$ is zero.
(b) The matrix $A$ is nilpotent if and only if […]

Is the Product of a Nilpotent Matrix and an Invertible Matrix Nilpotent?
A square matrix $A$ is called nilpotent if there exists a positive integer $k$ such that $A^k=O$, where $O$ is the zero matrix.
(a) If $A$ is a nilpotent $n \times n$ matrix and $B$ is an $n\times n$ matrix such that $AB=BA$. Show that the product $AB$ is nilpotent.
(b) Let $P$ […]

True or False: Eigenvalues of a Real Matrix Are Real Numbers
Answer the following questions regarding eigenvalues of a real matrix.
(a) True or False. If each entry of an $n \times n$ matrix $A$ is a real number, then the eigenvalues of $A$ are all real numbers.
(b) Find the eigenvalues of the matrix
\[B=\begin{bmatrix}
-2 & […]

Every Diagonalizable Nilpotent Matrix is the Zero Matrix
Prove that if $A$ is a diagonalizable nilpotent matrix, then $A$ is the zero matrix $O$.
Definition (Nilpotent Matrix)
A square matrix $A$ is called nilpotent if there exists a positive integer $k$ such that $A^k=O$.
Proof.
Main Part
Since $A$ is […]

Is a Set of All Nilpotent Matrix a Vector Space?
Let $V$ denote the vector space of all real $n\times n$ matrices, where $n$ is a positive integer.
Determine whether the set $U$ of all $n\times n$ nilpotent matrices is a subspace of the vector space $V$ or not.
Definition.
An matrix $A$ is a nilpotent matrix if […]