A locally injective but non globally injective function?

A continuous function $f : U \subset \mathbb{R}^n \to \mathbb{R}^n$, is said to be locally injective at $x_0 \in U$ if exist a neighborhood $V \subset U$ of $x_0$ s.t. $f|_V$ is injective. $f$ is said to be locally injective on $U$ if is locally injective at all points of $U$.

If $n=1$, clearly $f$ is locally injective on $U$ iff it's injective on $U$. If $n >1$, this is false (at least is what I believe).

Does anybody know a counterexample i.e. a continuous function which is locally injective on an open $U$ set but it's not injective on $U$?

[observation] if $f$ is locally injective, by the invariance domain theorem is a local homeomorphism. if $f$ is also proper (i.e. the counter-image of a compact set is compact), then it's also a global homeomorphism (Caccioppoli theorem), and consequently injective. This means the counterexample cannot be a proper map.

[edit] I forgot to specify that I was interested in continuous functions.


An easy way to find such an example is to take any non-constant holomorphic function $f:U \to \mathbb{C}$ and throw away the points where $f' = 0$. A holomorphic function is locally injective if $f'(z) \neq 0$, so we need only ensure that the function is not globally injective.

As I pointed out in a comment, we can take $U = \mathbb{C} \smallsetminus \{0\}$ and $f(z) = z^n$ for $n \geq 2$. Or, if you prefer, $f(z) = e^z$ on all of $\mathbb{C}$ for the most simple-minded examples.

These examples are easily extended to $\mathbb{R}^n$, $n \geq 2$, simply by writing $\mathbb{R}^n = \mathbb{C} \times \mathbb{R}^{n-2} \ni(z,v)$ and considering $g(z,v) = (f(z), v)$. I'll leave it to your creativity to build many more and more interesting examples.