Example 2 For a four-digit number, at most two of its digits are different. How many such four-digit numbers are there?

保留源文本的换行和格式，所以翻译结果如下：

Example 2 For a four-digit number, at most two of its digits are different. 
Ask: How many such four-digit numbers are there?
Solution: Clearly, there are exactly 9 four-digit numbers where all four digits are the same.

Below, we consider four-digit numbers with exactly two different digits in three steps.
(1) First, consider the thousands place, which has 9 possible choices: $1,2, \cdots, 9$.
(2) Next, consider the hundreds, tens, and units places. Since there are exactly two different digits, choose 1 digit from $0,1, \cdots, 9$ in addition to the thousands place digit.
(3) After determining the two digits in the first two steps, further determine the digits in the hundreds, tens, and units places. Each of these positions has two choices, but one scenario must be excluded, where the digits in the hundreds, tens, and units places are all the same as the thousands place digit, so there are $2 \times 2 \times 2-1$ ways to choose.
In summary, there are a total of four-digit numbers
$$
9+9 \times 9(2 \times 2 \times 2-1)=576 \text { (numbers). }
$$