Definition: Let $g$ be defined on all of $\mathbb{R}$. If $A$ is a subset of $\mathbb{R}$, define
$$g^{-1}(A)=\{ x\in\mathbb{R}:~ g(x)\in A\}$$
True or false:
If $g$ is continuous and $A$ is a closed set and $A\subset \mathbb{R}$, then $g^{-1}(A)$ is closed.
This problem is found from Understanding Analysis (Ex.4.4.12(d), by Abbott, Stephen). I found the answer from internet showing this statement is True. But can I use the following counter-example?
$$\begin{align} g(x)&=3x-1,~x\in[1/3,~2/3]\\ \\ g(x)&=1, ~~~~~~~~~~x\in (2/3,1)\\ \\ g(x)&=0,~~~~~~~~~~x\in(0,1/3) \end{align}$$
So $A=[0,1]$ is closed. But $g^{-1}(A)=(0,1)$ is not closed.