Solution (source code)

= Solution

View infinity as the puncture of the Riemann sphere and consider $g(1/z)$ near $z=0$. If this map had an essential singularity, the <Great Picard theorem> in a coordinate chart would make almost every nearby value occur infinitely often, contradicting the injectivity of $g$. The singularity is therefore removable as a map into the compact Riemann surface $R$, and $g$ extends to a nonconstant holomorphic map
$$
\widetilde g:\mathbb P^1\longrightarrow R.
$$
The extension is injective. A collision between $\widetilde g(\infty)$ and $g(z_0)$, or local degree greater than one at infinity, would give nearby values two distinct preimages by the local normal form of a nonconstant holomorphic map, again contradicting injectivity on $\mathbb C$. Thus $\widetilde g$ is a holomorphic bijection between compact Riemann surfaces and hence a biholomorphism. Therefore $R\cong\mathbb P^1$, whose genus is zero.