How prove $f(x)$ is monotonous , if $f'(x)=g[f(x)]$ Question:

Let $f(x)$ be a derivative, and there exsit $g(x)$ be such that:
  $$f'(x)=g[f(x)]$$
  Show that $f(x)$ is monotonic.

This problem is from Xie Hui Min analysis problems book in china ,and the 
The author only give the hint: use contradiction.

My idea: Assume there exist $x,y$ such that: 
$$f(x)=f(y), x\neq y$$
Then:
$$f'(x)=g(f(x))\Longrightarrow f'(y)=g(f(y))=g(f(x))=f'(x).$$
Then I can't continue. Thank you
 A: If $f(x)$ exists everywhere and $g(y)$ exists over the entire range of $f(x)$, then $f'(x)$ exists everywhere and $f(x)$ must therefore be continuous everywhere.  We'll assume this is the case.
Assume $f(x)$ has a local maximum at $x_0$:


*

*$f'(x_0) = 0$

*There exists $x_1 < x_0$ where $f(x_1) < f(x_0)$

*There exists $x_2 > x_0$ where $f(x_2) < f(x_0)$


Also, there are no other extrema between $x_1$ and $x_2$.
Pick $x_3$ and $x_4$ such that $x_1 < x_3 < x_0 < x_4 < x_2$ and $f(x_3) < f(x_0)$ and $f(x_4) = f(x_3)$.  Since $f(x)$ is continuous, this must be possible.
Since there are no other extrema between $x_3$ aned $x_4$, we must have $f'(x) \geq 0$ for $x_3 < x < x_0$ and $f'(x) \leq 0$ for $x_0 < x < x_4$.
Thus, we must have $g(y) \geq 0$ for $f(x_3) < y < f(x_0)$ and $g(y) \leq 0$ for $f(x_0) > y > f(x_4)$.  But $f(x_3) = f(x_4)$ so these two ranges are the same.  We must have $g(y) = 0$ for $f(x_3) < 0 < f(x_0)$, which would mean we must have  $f(x_3) = f(x_0)$, which contradicts our original assumption that there is a local maximum.
The same argument holds for the assumption of a local minimum.
So $f(x)$ cannot have any local maximum or local minimum anywhere, and thus must be monotonic.
