Example 2 Given $f(x)=\left\{\begin{array}{cc}x^{2}-1, & 0 \leqslant x \leqslant 1, \\ x^{2}, & -1 \leqslant x<0 .\end{array}\right.$ Find $f^{-1}(x)$.
When $0 \leqslant x \leqslant 1$, $y=x^{2}-1 \in[-1,0]$, from which we get $x=\sqrt{y+1}(-1 \leqslant y \leqslant 0)$;
When $-1 \leqslant x<0$, $y=x^{2} \in(0,1)$, from which we get $x=-\sqrt{y}(0<y \leqslant 1)$.
Therefore, the inverse function is $f^{-1}(x)=\left\{\begin{array}{l}\sqrt{x+1},(-1 \leqslant x \leqslant 0), \\ -\sqrt{x},(0<x \leqslant 1) .\end{array}\right.$
Solution notes: A complete function consists of the formula (correspondence rule) and the domain, neither of which can be missing. When finding the inverse function, do not forget to write down the domain. The range of the original function is the domain of the inverse function.